Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/recksjs/redogs
🦆 Redux-like store on RxJS with effects
https://github.com/recksjs/redogs
effects redux rxjs typescript
Last synced: 2 months ago
JSON representation
🦆 Redux-like store on RxJS with effects
- Host: GitHub
- URL: https://github.com/recksjs/redogs
- Owner: recksjs
- License: mit
- Created: 2019-12-01T11:20:56.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-07T12:20:52.000Z (about 2 years ago)
- Last Synced: 2024-11-08T04:41:38.664Z (3 months ago)
- Topics: effects, redux, rxjs, typescript
- Language: TypeScript
- Homepage:
- Size: 490 KB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Redogs
Redux-like store with RxJS Observable output and effects
```
npm i redogs
```## Basic usage
```js
import { createStandardAction, createStore, getType, isActionOf } from 'redogs';
import { filter, map, tap, withLatestFrom } from 'rxjs/operators';// create reusable action creators
const incrementAction = createStandardAction('INCREMENT')();
const decrementAction = createStandardAction('DECREMENT')();
const resetAction = createStandardAction('RESET')();// create a store
const store = createStore(reducer, effect);// listen to the state updates
store.state$.subscribe(state => {
console.log(state);
});// dispatch actions
store.dispatch(incrementAction());
store.dispatch(incrementAction());
store.dispatch(decrementAction());
store.dispatch(resetAction(42));// A reducer
function reducer(action, state = 0) {
switch (action.type) {
case (getType(incrementAction)): {
return state + 1;
}
case (getType(decrementAction)): {
return state + 1;
}
case (getType(resetAction)): {
return action.payload;
}
default:
return state;
}
}// an effect
function effect(actions$, state$) {
return actions$.pipe(
filter(isActionOf([incrementAction])),
withLatestFrom(state$),
tap(([action, state]) => {
// perform sideeffects
console.log('Action', action.type);
console.log('Payload', action.payload);
console.log('State', state);
}),
map(() => {
// or generate another action
return { type: 'ANOTHER_ACTION' };
})
)
}
```