Kanso is a light-weight state-management library for web applications. Kanso's philosophy is to provide simple mechanics that can be used at your own discretion. You can use these patterns in many ways. Kanso molds to the skill of the user.
"By removing the non-essential and ornate, we can express a bare and honest simplicity."
npm install --save @zenwolf/kanso
Kanso focuses on encapsulating state and logic, separating them from any UI layer. State is maintained in a single place and can be passed into another system for processing or rendering.
Kanso shapes the world: something else can render it into the visible realm.
Kanso defines no specific UI, allowing you to use any UI technology you like. Your UI of choice will need to accept the entire state and use it as it sees fit. The UI will need to be able to create actions and dispatch them on the app object using the App#dispatch
method.
- Unidirectional data flow that operates solely on actions/commands.
- Immutable state managed by state data stores.
- Interceptors to extend the core system:
- action interceptors -- allow you to act upon an action or change the action/replace it before it is passed to stores and used to modify state.
- state interceptors -- allow you to act upon a new state before it is set, or change it/replace it, before change listeners are called.
- Standard way to define state queries using
QueryApi
generator, which can be used statelessly(static methods) or statefully(bound to a specific state snapshot).
Kanso gives you different ways to respond to changes:
- Intercept actions.
- Listen to state changes.
Interceptors are all composed into a single function call. The intial value is passed as the argument, and each function returns the same value type that is passed as the arugment to the next interceptor, until you end up with a single, resulting value which is then processed by the application.
An action interceptor is a function that allows you to receive an action before it is used to change state. The required function signature is:
action => action
You can return the same action, you could return a different action, or you could return a modified version of the same action. This is an extremely flexible system, hopefully allowing you to perform any number of things in response to an action.
A state interceptor is a function that allows you to receive a new state before it is set. The required function signature is:
state => state
Much like an action interceptor, you can return the same state, return a different state, or return a modified version of the same state.
Here are some strategies related to working with UI.
Kanso is written in ES6 and uses Babel to generate ES5 JS code. You run a build command to generate the resulting library from src
into the lib
folder.
npm run build
Kanso uses eslint to lint code.
npm run lint
Kanso uses mocha for unit tests.
npm test
npm run verify