1.2.3 • Published 3 years ago
rxstore-watch v1.2.3
RxStore Watch
A state management tool using RxJS
This project is currently in development.
Usage:
import { createRxStore, applyMiddleware } from 'rxstore-watch'
import { mapTo } from 'rxjs/operators'
const initialState = {
counter: 0,
pinging: false
}
const reducer = (state = initialState, action) => {
switch (action.type) {
case 'INCREMENT': return { ...state, counter: state.counter + 1 }
case 'DECREMENT': return { ...state, counter: state.counter - 1 }
case 'PING': return { ...state, pinging: true }
case 'PONG': return { ...state, pinging: false }
default: return state
}
}
const store = createRxStore(reducer, initialState, applyMiddleware(yourAwesomeMiddleware))
store.subscribe(currentState => {
console.log('Current state: ', currentState) // { counter: 0, pinging: false }
})
store.dispatch({ type: 'INCREMENT' }) // { counter: 1, pinging: false }
// Create a watcher. 'PONG' will be dispatched everytime we dispatch 'PING' action.
store.addWatcher('PING', pipe => pipe(
mapTo({ type: 'PONG' })
))
store.dispatch({ type: 'PING' }) // { counter: 1, pinging: true }
console.log('Current state: ', store.getState()) // { counter: 1, pinging: false }
1.2.0
3 years ago
1.1.9
3 years ago
1.2.3
3 years ago
1.2.2
3 years ago
1.2.1
3 years ago
1.1.8
3 years ago
1.1.7
3 years ago
1.1.6
3 years ago
1.1.5
3 years ago
1.1.4
3 years ago
1.1.3
3 years ago
1.1.2
3 years ago
1.1.1
3 years ago
1.1.0
3 years ago
1.0.9
3 years ago
1.0.8
3 years ago
1.0.7
3 years ago
1.0.6
3 years ago
1.0.5
3 years ago
1.0.4
3 years ago
1.0.3
3 years ago
1.0.2
3 years ago
1.0.1
3 years ago
1.0.0
3 years ago