Skip to content

Commit

Permalink
Data: add a comment about why we normalize resolvers to objects with …
Browse files Browse the repository at this point in the history
…fulfill method (#25102)

Also refactors the code to remove too smart destructuring, and removes a stale JSDoc comment.
  • Loading branch information
jsnajdr authored Sep 7, 2020
1 parent 84cbc5f commit afc0090
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions packages/data/src/namespace-store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,13 +252,21 @@ function mapActions( actions, store ) {
* @param {Object} resolvers Resolvers to register.
* @param {Object} selectors The current selectors to be modified.
* @param {Object} store The redux store to which the resolvers should be mapped.
* @param {Object} queue Resolvers async queue.
* @param {Object} resolversCache Resolvers Cache.
*/
function mapResolvers( resolvers, selectors, store, resolversCache ) {
// The `resolver` can be either a function that does the resolution, or, in more advanced
// cases, an object with a `fullfill` method and other optional methods like `isFulfilled`.
// Here we normalize the `resolver` function to an object with `fulfill` method.
const mappedResolvers = mapValues( resolvers, ( resolver ) => {
const { fulfill: resolverFulfill = resolver } = resolver;
return { ...resolver, fulfill: resolverFulfill };
if ( resolver.fulfill ) {
return resolver;
}

return {
...resolver, // copy the enumerable properties of the resolver function
fulfill: resolver, // add the fulfill method
};
} );

const mapSelector = ( selector, selectorName ) => {
Expand Down

0 comments on commit afc0090

Please sign in to comment.