Actionizer
This is just pub/sub for data flow like Redux.
Overview
Command -> (Web API)
^ _________|
| v
Action -> Command -> (Reducer) -> Store -> View
^ |
|_________________________________________|
Dependencies
babel-polyfill
for ES2015 generator.
Installation
$ npm i --save actionizer
Usage
;;;;;; const initialState = ; // Customize notifier.const notify = ; // Create "Store", it treats states for the app.const store = ; // Define "Reducer"const setCount = state; // Define "Action Creator".const count = { // Get current state. const state = ; // Update state by "Reducer" ;} // API request.const getItems = { return axios;}; // Define asynchronous "Action Creator".const fetchItems = { try // "call" receives a function and arguments that returns a promise. const result = ; // Do something... catche // Do something... } const sleep = { return { ; };}; // Define debounced "Action Creator".const debouncedFetchItems = { ; // Delegate other action creator ;}let actionId;const searchItemsById = { ; actionId = ;} // Subscribe store's change.const unsubscribe = store; // Dispatch "Action".store; // => listener: 100 // Unsubscribe store's change.;
API
Top level API
createStore(initialState, notify)
Create a store.
compose(...funcs)
Composes functions from right to left.
Store API
subscribe(listener)
Register a listener of store's changes. And it returns unsubscriber.
dispatch(action, callback)
Trigger an action. In Actionizer, "Action" is a generator like:
// This is "Action Creator"const count = { ;} // This is "Action"const action = ;
getState()
Get store's state.
Command API
"Command" return a payload used in "Action Creator".
select(selector = (state) => state)
select
calls selector
with current state, and return selector
result.
reduce(reducer, ...args)
reduce
updates state by result of reducer
.
call(fn, ...args)
call
calls fn
with args
.
fn
should return Promise
.
call
returns resolved value.
fork(actionCreator, ...args)
fork
calls an action without blocking and returns action id.
Action id is unique.
delegate(actionCreator, ...args)
delegate
delegates process to other action by calling action creator.
cancel(actionId)
cancel
cancels action by action id.
Related projects
LICENSE
MIT