https://github.com/lucifier129/sukkula
A state-management library aims to combine the best parts of redux and rxjs
https://github.com/lucifier129/sukkula
react react-hooks redux redux-observable rxjs state-management
Last synced: about 1 year ago
JSON representation
A state-management library aims to combine the best parts of redux and rxjs
- Host: GitHub
- URL: https://github.com/lucifier129/sukkula
- Owner: Lucifier129
- License: mit
- Created: 2020-03-16T09:08:40.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-03-16T21:35:17.000Z (over 6 years ago)
- Last Synced: 2025-05-01T17:19:00.816Z (about 1 year ago)
- Topics: react, react-hooks, redux, redux-observable, rxjs, state-management
- Language: JavaScript
- Size: 379 KB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# sukkula
> A state-management library aims to combine the best parts of redux and rxjs
[](https://www.npmjs.com/package/sukkula)
## Install
```bash
npm install --save sukkula
```
## Usage
```tsx
import { setupState, setupEffect, createStore } from 'sukkula'
import { interval } from 'rxjs'
import { map, switchMap, takeUntil } from 'rxjs/operators'
// define setup function
let setupCounter = (initialCount = 0) => {
// setup state via initialState and reducers
let { state$, actions } = setupState({
state: initialCount,
reducers: {
incre: state => state + 1,
decre: state => state - 1
}
})
// setup effect action for stopping
let stop = setupEffect()
// setup effect action for starting
let start = setupEffect(input$ => {
return input$.pipe(
switchMap((period = 1000) => {
return interval(1000).pipe(
map(() => actions.incre()),
takeUntil(stop.input$)
)
})
)
})
// return the pair { state$, actions }
return {
state$,
// merge pure-actions and effect-actions
actions: {
...actions,
start,
stop
}
}
}
let store = createStore(() => {
return setupCounter(10)
})
store.state$.subscribe(state => {
console.log('state', state)
})
store.actions.start()
```
## License
MIT © [Lucifier129](https://github.com/Lucifier129)