1.2.3 • Published 5 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
5 years ago
1.1.9
5 years ago
1.2.3
5 years ago
1.2.2
5 years ago
1.2.1
5 years ago
1.1.8
5 years ago
1.1.7
5 years ago
1.1.6
5 years ago
1.1.5
5 years ago
1.1.4
5 years ago
1.1.3
5 years ago
1.1.2
5 years ago
1.1.1
5 years ago
1.1.0
5 years ago
1.0.9
5 years ago
1.0.8
5 years ago
1.0.7
5 years ago
1.0.6
5 years ago
1.0.5
5 years ago
1.0.4
5 years ago
1.0.3
5 years ago
1.0.2
5 years ago
1.0.1
5 years ago
1.0.0
5 years ago