https://github.com/joduplessis/sourcex
A Redux inspired state management library, based on an Rx-flavoured subscriber model.
https://github.com/joduplessis/sourcex
experimental idea javascript
Last synced: 3 months ago
JSON representation
A Redux inspired state management library, based on an Rx-flavoured subscriber model.
- Host: GitHub
- URL: https://github.com/joduplessis/sourcex
- Owner: joduplessis
- License: mit
- Created: 2020-09-06T17:13:45.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-09-08T09:06:01.000Z (over 5 years ago)
- Last Synced: 2024-12-26T00:23:06.646Z (about 1 year ago)
- Topics: experimental, idea, javascript
- Language: HTML
- Homepage: https://joduplessis.com
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# SourceX
A Redux inspired state management library, based on an Rx-flavoured subscriber model.
> ⚠️ Warning! Don't use in production! None or all of the API's might change. Strictly playground exercise material.
# Example usage
All the code is in `index.html`.
### Define your reducers
```
const user = (state = { name: "Jon Doe" }, action) => {
switch (action.type) {
case 'UPDATE_NAME':
return { ...state, name: action.payload.name }
default:
return state
}
}
const page = (state = { title: "Default" }, action) => {
switch (action.type) {
case 'UPDATE_TITLE':
return { ...state, title: action.payload.title }
default:
return state
}
}
createReducers(user, page)
```
### Subscribe to changes
```
onStateUpdate(state => {
console.log('Got a notification about a state update. New value: ', state)
})
```
### Dispatch updates
```
dispatch({ type: 'UPDATE_NAME', payload: { name: 'Jo du Plessis' } })
dispatch({ type: 'UPDATE_TITLE', payload: { title: 'The beginning...' } })
```