Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/deebloo/redux-web-worker
Redux implementation in a web worker
https://github.com/deebloo/redux-web-worker
Last synced: 3 months ago
JSON representation
Redux implementation in a web worker
- Host: GitHub
- URL: https://github.com/deebloo/redux-web-worker
- Owner: deebloo
- License: mit
- Created: 2016-07-02T23:43:36.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-12-15T08:16:42.000Z (about 1 year ago)
- Last Synced: 2024-10-05T13:07:45.360Z (3 months ago)
- Language: JavaScript
- Size: 45.9 KB
- Stars: 7
- Watchers: 4
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# redux-worker [![CircleCI](https://circleci.com/gh/deebloo/redux-web-worker.svg?style=svg)](https://circleci.com/gh/deebloo/redux-web-worker)
```
npm i --save redux-web-worker
```Redux implementation in a web worker (experiment).
The entire state is kept in a separate thread. (this also gives the added benefit of immutable objects)```TS
import { createStore } from 'redux-web-worker/core';
// Or if using bundle.
// var createStore = Rw.createStore;// the reduces is run in a new thread
var store = createStore((state, action) => {
switch(action.type) {
case 'INCREMENT':
return state + 1;
case 'DECREMENT':
return state - 1;
default:
return state;
}
}, 0);// get state has to be async since the state is managed is a separate thread
store.getState(state => {
console.log(state) // 0
});// subscribe to the store for changes.
// the web worker acts as the dispatcher with onmessage and postMessage
store.subscribe(state => {
console.log(state);
});// standard redux style dispatch
store.dispatch({ type: 'INCREMENT' });
```