mirror of
https://github.com/reduxjs/redux-devtools.git
synced 2024-11-15 22:26:53 +03:00
6782f4ae41
* Move extension * prettier
35 lines
940 B
JavaScript
35 lines
940 B
JavaScript
const { createStore } = require('redux');
|
|
|
|
const INCREMENT_COUNTER = 'INCREMENT_COUNTER';
|
|
const DECREMENT_COUNTER = 'DECREMENT_COUNTER';
|
|
|
|
const initialState = { value: 0 };
|
|
|
|
const store = createStore(
|
|
(state, action) => {
|
|
switch (action.type) {
|
|
case INCREMENT_COUNTER:
|
|
return { value: state.value + 1 };
|
|
case DECREMENT_COUNTER:
|
|
return { value: state.value - 1 };
|
|
default:
|
|
return state;
|
|
}
|
|
},
|
|
initialState,
|
|
window.__REDUX_DEVTOOLS_EXTENSION__
|
|
? window.__REDUX_DEVTOOLS_EXTENSION__()
|
|
: (noop) => noop
|
|
);
|
|
|
|
const el = document.getElementById('counter');
|
|
|
|
store.subscribe(() => {
|
|
el.innerHTML = store.getState().value;
|
|
});
|
|
|
|
const increment = document.getElementById('increment');
|
|
const decrement = document.getElementById('decrement');
|
|
increment.onclick = () => store.dispatch({ type: INCREMENT_COUNTER });
|
|
decrement.onclick = () => store.dispatch({ type: DECREMENT_COUNTER });
|