IMPR: Redux compatibilities

This commit is contained in:
Tony Air 2021-08-10 01:27:45 +02:00
parent 1404ea8ff9
commit cdb64dbddd
6 changed files with 63 additions and 0 deletions

View File

@ -0,0 +1,5 @@
import PageControls from './page-controls';
export {
PageControls,
};

View File

@ -0,0 +1,6 @@
export default class PageControls {
constructor(store) {
console.log('page-controls init');
console.log(store);
}
}

View File

@ -0,0 +1,8 @@
import {
createStore,
} from 'redux'
import reducers from './reducers'
export default function configure() {
return createStore(reducers)
}

19
src/js/store/index.js Normal file
View File

@ -0,0 +1,19 @@
import configure from './configure'
const store = configure();
/*import {
PageControls
} from './components'*/
//const pageControls = new PageControls(store)
store.subscribe(() => console.log(store.getState()));
store.dispatch({
type: 'counter/incremented',
})
store.dispatch({
type: 'counter/incremented',
})
store.dispatch({
type: 'counter/decremented',
})

View File

@ -0,0 +1,16 @@
export default function counter(state = {
value: 0,
}, action) {
switch (action.type) {
case 'counter/incremented':
return {
value: state.value + 1,
}
case 'counter/decremented':
return {
value: state.value - 1,
}
default:
return state
}
}

View File

@ -0,0 +1,9 @@
import {
combineReducers,
} from 'redux'
import counter from './counter';
export default combineReducers({
counter,
});