Nanux
State, actions and middlewares in just 1 KB
Installation
Fast guide
Vue integration
TODO
Installation
yarn add nanux
npm install nanux
Fast guide
Create a store
const store = state: 1 actions: state + value
Get state
const store = state: a: 1 b: 2 store // => { a: 1, b: 2 }
NOTE: It returns a shallow clone of objects to deny side effects.
But you still can mutate deep properties.
Dispatch actions
store // => 6
NOTE:
dispatch
returns new state or Promise with new state
Subscribe/unsubscribe to changes
const cb = store
Using middlewares
const store = state: 1 actions: state + value state - value middlewares: action: "minus" payload store // => -4
NOTE: if middleware returns
null
, action and all next middlewares will be aborted.
Asynchronous actions/middlewares
const store = state: 1 actions: middlewares:
Dispatch another actions inside action
const store = state: isFetching: false items: actions: ...state isFetching return
Vue integration
Usage
Install mixin
Vue
Add store modules to your components
stores: moduleA moduleB
$store
Use this$storemoduleAstatethis$storemoduleA
NOTE:
dispatch
triggers$forceUpdate
to apply changes
TODO
Global
- Add advanced events guide to README.md
- Getters
- Modules (?)
- Write tests/types
Vue
- Deep-pass of store modules (maybe
provide/inject
?) - Add mapState/mapActions helpers
License
MIT