redux-devtools/packages/redux-devtools-remote/examples/node-counter/index.js

29 lines
611 B
JavaScript
Raw Permalink Normal View History

2021-10-28 23:39:47 +03:00
var createStore = require('redux').createStore;
var devTools = require('remote-redux-devtools').default;
function counter(state, action) {
if (state === undefined) state = 0;
switch (action.type) {
case 'INCREMENT':
return state + 1;
case 'DECREMENT':
return state - 1;
default:
return state;
}
}
var store = createStore(counter, devTools({ realtime: true }));
store.subscribe(function () {
console.log(store.getState());
});
function incrementer() {
setTimeout(function () {
store.dispatch({ type: 'INCREMENT' });
incrementer();
}, 1000);
}
incrementer();