Skip to content

Commit

Permalink
Add documentation for the refreshResourceTemplate reducer function
Browse files Browse the repository at this point in the history
  • Loading branch information
jgreben committed Jun 19, 2019
1 parent 882259a commit 66b6977
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/reducers/index.js
Expand Up @@ -67,6 +67,18 @@ export const populatePropertyDefaults = (propertyTemplate) => {
}))
}

/**
* The purpose of this function is to fill out the resource state tree with initial and additional properties,
* also calling the function to fill in the default values for those properties. This is called when a new top-level
* resource template is initialized and also when a property template with a nested resource is initialized
* (by expanding the property in a panel).
*
* Whenever a new resource template is initialized, the reduce method (bound to the lastObject variable) will by default
* append it to the `newState` accumulator, so before everything we must pop out the latest resource id and set that
* as the only resource in the state tree.
*
* @returns {{}} the new state of the redux store.
*/
export const refreshResourceTemplate = (state, action) => {
const resourceTemplateId = Object.keys(state.resource).pop()
const newResource = { resource: { [resourceTemplateId]: state.resource[resourceTemplateId] } }
Expand Down

0 comments on commit 66b6977

Please sign in to comment.