Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tflx/state-machine
https://github.com/tflx/state-machine
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/tflx/state-machine
- Owner: tflx
- Created: 2019-04-23T11:10:12.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-04-25T08:30:19.000Z (over 5 years ago)
- Last Synced: 2024-04-23T13:39:16.434Z (9 months ago)
- Language: JavaScript
- Size: 71.3 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# State Machine
Based on https://github.com/andybelldesign/beedle which is based on this article https://css-tricks.com/build-a-state-management-system-with-vanilla-javascript/
## Publish state change
```javascript
import store from './store/index.js';store.dispatch('addItem', 'A new item');
```## Subscribe to state change
```javascript
import store from './store/index.js';constructor() {
store.subscribe('stateChange', () => this.render());
}render = () => {
console.log(store.state.items);/**
Compare to local state and update/re-render if necessary
*/
}
```