A promise-based, middleware-driven, express-like and immutable built-in state management
Features
- Immutable state and operations, see Immutable State
- Express-like and promise-based middlewares and routers, see Middleware and Router
Example
store.js
file:
const router = ;const createStore = ;const store = ;store
router.js
file:
const Router = ;const router = ;routerall'/add-task' async { const store = req text = reqbody; const result = await const id = result; store;};routerall'/toggle-task' { const store = req id = reqbody; store;};
TodoListPage.js
file:
const PureComponent PropTypes = ;const connect = ; static propTypes = tasks: PropTypesarrayisRequired dispatch: PropTypesfuncisRequired { return } { return } { return <button onClick=thisonPressAddTask>Add Task</button> <ul> thispropstasks </ul> } TodoListPage
index.js
file:
const ReactDom = ;const Provider = const store = ;const TodoListPage = ; ReactDom;
Immutable State
State is immutable by using immutable-state. Most operations are like immutable-js.
You must use mutation methods(like .set()
, .remove()
) in store.mutate()
, while others(like .get()
, .filter()
) are not.
store.mutate(callback)
Start a new mutation operation. You should call all mutation methods in callback
function. callback
should use sync code, no promise or async/await
.
.get(keysPath)
.set(keysPath)
Middleware
store.use((req, resp, next)=>{})
Router
See uni-router
Contributing
Checkout the CONTRIBUTING.md if you want to help
License
Licensed under MIT
Copyright (c) 2017 Tian Jian