Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hiro08gh/hobby-redux
Small state management like Redux. It's a hobby.
https://github.com/hiro08gh/hobby-redux
Last synced: 7 days ago
JSON representation
Small state management like Redux. It's a hobby.
- Host: GitHub
- URL: https://github.com/hiro08gh/hobby-redux
- Owner: hiro08gh
- Created: 2020-07-13T08:47:56.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-12-02T16:18:46.000Z (26 days ago)
- Last Synced: 2024-12-17T08:58:46.077Z (11 days ago)
- Language: TypeScript
- Homepage:
- Size: 82 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# hobby-redux
Small configuration state management like Redux. It's a hobby.
## Usage
```typescript
import { Store } from './store';type CounterAction = { type: 'INCREMENT' } | { type: 'DECREMENT' };
const reducer = (state: number = 0, action: CounterAction) => {
switch (action.type) {
case 'INCREMENT':
return state + 1;
case 'DECREMENT':
return state - 1;
default:
return state;
}
};const store = new Store(reducer);
const incrementAction = { type: 'INCREMENT' };
const decrementAction = { type: 'DECREMENT' };store.subscribe(fn);
function fn() {
console.log(store.getState());
}// Add to the numbers + 1
store.dispatch(incrementAction); // => 1
store.dispatch(incrementAction); // => 2// Subtract numbers -1
store.dispatch(decrementAction);// => 1
```## test
```bash
$ npm run test
```## build
```bash
$ npm run build
```## Author
[@hiro08gh](https://github.com/hiro08gh)