Learning Redux.js and building a demo app.
I have a reducer set like this:
// Imports here function blocksFunc(state = [], action) { switch (action.type) { case 'ADD_BLOCK': _id++; return [...state, {'_class' : 'basic', '_id' : _id }]; default: state = []; return state; } } const BlockGeneratorReducer = combineReducers({ blocksFunc, }); export default BlockGeneratorReducer;
I successfully update the state, but when logging I get the following when page loads:
blocksFunc() type: "@@redux/INIT"
blocksFunc() type: "@@redux/PROBE_UNKNOWN_ACTION_b.f.4.q.y.o.a.v.2.t.9"
blocksFunc() type: "@@redux/INIT"
So blocksFunc function is launched three times with default action.type. On which occasions is the action type "@@redux/INIT" launched? What might "@@redux/PROBE_UNKNOWN_ACTIOM" refer in to?
The full source can be found on git: https://github.com/JaakkoKarhu/redux-react-blockgenerator
The working demo is uploaded to my server: http://jaakkokarhu.com/playground/redux-block-generator/
Since being new with React and Redux, all the other comments regarding the source are also very welcome.
EDIT:
blocksFunc() edited according to DavidWalshes advice.
One frequently asked question is whether Redux "calls all reducers" when dispatching an action. Since there really is only one root reducer function, the default answer is "no, it does not".
Creating the Root Reducer A Redux app really only has one reducer function: the "root reducer" function that you will pass to createStore later on. That one root reducer function is responsible for handling all of the actions that are dispatched, and calculating what the entire new state result should be every time.
Introduction. In Redux, a reducer is a pure function that takes an action and the previous state of the application and returns the new state. The action describes what happened and it is the reducer's job to return the new state based on that action.
Reducers: As we already know, actions only tell what to do, but they don't tell how to do, so reducers are the pure functions that take the current state and action and return the new state and tell the store how to do.
@@redux/INIT is launched twice on purpose. First time is for testing combineReducers, second one is actual init: https://github.com/reactjs/redux/issues/382
As TenorB pointed out on question comments, @@redux/PROBE_UNKNOWN_ACTION is also launched for testing purpose.
So, after all, these events are not accidentally launched.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With