This package has been deprecated

Author message:

We

rxstore-watch
TypeScript icon, indicating that this package has built-in type declarations

1.2.3 • Public • Published

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 }

Readme

Keywords

none

Package Sidebar

Install

npm i rxstore-watch

Weekly Downloads

1

Version

1.2.3

License

ISC

Unpacked Size

73.3 kB

Total Files

38

Last publish

Collaborators

  • blankart