Basically re-implemented the Redux API without ES6 syntax and some of the top-level API exports.
atomfunction. It cannot be mutated outside of the atom function.
switch actiontypecase 'INCREMENT':return state + 1;case 'DECREMENT':return state - 1;case 'INCREMENT_ASYNC':returnsetTimeoutdispatchtype: 'INCREMENT';1000;;default:return state;var store = atomcounter 0;storesubscribeconsole.logstoregetState;storedispatch type: 'INCREMENT' ; // 1storedispatch type: 'INCREMENT' ; // 2storedispatch type: 'DECREMENT' ; // 1storedispatch type: 'INCREMENT_ASYNC' ; // 2
Creates your atom
store that contains your application state. Returns an Object with methods for interacting with your state.
A function that accepts
function(state, action) and returns the potentially modified
state. You can also return a function with the signature
function(dispatch) for performing asynchronous tasks before modifying the state. When your async task completes, the passed in
dispatch function can be called with an "action" that results your reducer returning a new state.
This calls your "reducer" with the current state and the given "action".
Add a function to be called anytime after your "reducer" has returned a new state. This is useful for logging changes or syncing to your storage or database.
You can add as many listeners as you would like.
Returns the current state. Useful for calling within a