mirror of
https://github.com/reduxjs/redux-devtools.git
synced 2024-12-04 07:23:52 +03:00
922985f9ea
* chore(deps): update dependency prettier to v3 * Format --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Nathan Bierema <nbierema@gmail.com>
35 lines
941 B
JavaScript
35 lines
941 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 });
|