https://github.com/julienetie/status
Basic state management
https://github.com/julienetie/status
Last synced: 13 days ago
JSON representation
Basic state management
- Host: GitHub
- URL: https://github.com/julienetie/status
- Owner: julienetie
- License: mit
- Created: 2021-04-08T23:02:33.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2021-04-09T00:54:22.000Z (almost 4 years ago)
- Last Synced: 2024-12-16T04:10:53.602Z (2 months ago)
- Language: JavaScript
- Size: 4.88 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- jimsghstars - julienetie/status - Basic state management (JavaScript)
README
# Status
Essential state management### why Status?
9 times out of 10 you will probably only need:
- set-state
- get-state
- subscribe
- unsubscribe### Example
```javascript
import status from 'status';status.set('dragon:animation', 'start');
status.get('dragon:animation'); // 'start'
status.subscribe('dragon:animation', 'moat', ({value}) => animateMoat(value));
status.unsubscribe('dragon:animation', 'moat'); // Removes moat from dragon:animation```
### What about async?
Ideally this should be handeled outside of state-machines.### Why no middleware?
Subscritions provide similar functionality but in a more granular way.### Multiple stores?
One store is the ideal goal. Multiple stores will have negligible difference to garbage collection.
Denoted namespaces can solve complexity issues.### why no DSL support
A lot can be achieved with one or two methods.
```javascript
state.set('nav', 'open');
state.subscribe(() => );
```
### Advanced (mutate)
Status has another method `status.mutate` which lets you directly overwrite the two core objects:
- store
- subscribers
-
It goes without saying, you should only touch this method if you know what you understand the risks. `mutate` is ideal for storing state in local storage as well as modifying the state when being retrieved from local storage.