Nation
🌍💻 A minimalist, functional state management library.
Features
- Functional: Nation enforces functional programming.
- Minimal: Nation is a fully functional state management lib weighing less than 500 byte.
- Easy: Nation's API is as minimal as possible.
- Immutable: State can only be set in actions or using
setState
. - Reactive: The update event is emitted on every state change.
Philosophy
State management libraries often weigh multiple kilobytes, even though most of the time you just need a small part of their API. Nation's approach is different - nation only includes the bare minimum state management functionality.
Nation enforces functional programming, this allows nation to be even tinier and makes you code more explicit.
Install
$ npm install nation
Usage
const nation = ; const ship = ; console;// => true
Actions
shipaction { swimming = val; } { name = val; }; ship;ship; console;// => 'merry' console;// => false
setState
State can also be set using ship console;// => 'enterprise' console;// => true
Computed properties
Computed properties can be accessed like normal state values. They are computed every time the state changes.
ship; console;// => 'The enterprise is swimming.'
Lifecycle
Nations lifecycle consists of a single method: onChange
.
ship;
Async actions
Nation treats every function the same no matter if it's sync or async. The only difference is, that in async functions you have to use setState
to set state.
shipaction setAsync: async { ship }; ship; // Wait console;
Nested state
Nation state can be nested, the onChange
event will be passed on, so even nested state is reactive.
Nested state cannot be set using actions, you have to use setState
.
const cargo = ; ship; ship cargo;// => Loaded state: false
License
MIT © Tobias Herber