Skip to content

Reductores

sonsoleslp edited this page Aug 22, 2018 · 8 revisions

Description

In Redux design guides, reductors should be, pure functions, in other words, they shouldn't have colateral efects and should be deterministics, given an entrance, the exit should be always the same. Precisely, the entrance to a reducting funtcion are a portion of the state and an action and exist is the new version of the state delivered and modified accordingly to the action.

Outside the "purity" requirement, other is that reductor always needs to return something. The main reason is because the state is built from results of different reducers, and it does not exist as in a different part and reconstructed upon the reducers results.

Redux provides a method called "combineReducers" its purpose is, given an special object, return an only reducer that takes everything else and that could be used to build the "warehouse". This special object is the one that describes the shape that the state will have, because it contains the reducer functions associated with a key. Therefore, when building the warehouse, it will called the method "combineReducers", that will call one by one different reducers specified without taking any argument and, because they are obliged to return always a value, the default value, that return will be the initial value for the state portion that are associated to. Afterwards, when an action is thrown, also this method will be called that will provide every reducer the last returned value (its state portion) and the thrown action. If is desired that the action affects this part of the state, then it will be returned a new version, else, the delivered.

Now, used reducers will be explain, not deeply:

Asigned key Name of the function Shape of result Function that makes
globalConfig globalConfig { title: New course, version: '1.0.0', difficulty: 'easy', ... } Global Config of the file
pageModalToggled togglePageModal {value: false, caller: "bo-124214"} Used to deploy the selection modal when creating a new one
boxesById boxesById {"bo-124214": caja0, "bo-124215": caja1} Creates the dictionary that containes all the boxes
boxSelected boxSelected "bo-124214" Tells the selected box
boxes boxesIds ["bo-124214", "bo-124215"] Creates the array of boxes identifiers
navItemsIds navItemsIds [0, "se-123321"] Creates the array of views identifiers
navItemSelected navItemSelected "se-123321" Tells the selected view
navItemsById navItemsById {0: seccion0, "se-123321": vista0} Creates the dictionary that contains every view
containedViewSelected containedViewSelected "cv-123321" Tells the selected contained view
pluginToolbarsById pluginToolbarsById {"bo-124214": bar0, "bo-124215": bar1} Creates the dictionary that contains every box toolbar
viewToolbarsById viewToolbarsById {"pa-124214": bar0, "pa-124215": bar1} Creates the dictionary that contains every view toolbar
exercises exercises {"pa-124214": quiz0, "pa-124215": quiz1} Creates the dictionary that contains the data model for the exercises
containedViewsById containedViewsById {"cv-123321": vista0, "cv-456321": vista1} Creates the dictionary that has every contained view
indexSelected indexSelected "se-123321" o "cv-123321" Tells the view or contained view selected by the index to be deleted, create brother/children views, etc.
Asigned key Name of the function Shape of result Function that makes

Also, there is the reducer _"sortableContainers" taht generates the property "sortableContainers of the EditorBox, but it doesn't belong to the general state else it is only invoked from the reducer "boxesById". As said before, reducers also attend to actions that consider convenient, in example, "boxesById" listens to the relative actions to EditorBox(create, deletes, modify, move, etc.) as the ones in the SortableContainer(creates, resizing, change rows and cells distribution, etc.) that's because correspondant reducer is contained inside.

Future improvement

Get better reducer nesting and better naming

Clone this wiki locally