Skip to content

Commit

Permalink
Data: Make resolver resolution async.
Browse files Browse the repository at this point in the history
  • Loading branch information
epiqueras authored and youknowriad committed Jul 15, 2020
1 parent a011ee6 commit de352f7
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions packages/data/src/namespace-store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ function mapResolvers( resolvers, selectors, store ) {
return selector;
}

let running = false;
const selectorResolver = ( ...args ) => {
async function fulfillSelector() {
const state = store.getState();
Expand All @@ -245,6 +246,7 @@ function mapResolvers( resolvers, selectors, store ) {

const { metadata } = store.__unstableOriginalGetState();
if (
running ||
metadataSelectors.hasStartedResolution(
metadata,
selectorName,
Expand All @@ -254,18 +256,22 @@ function mapResolvers( resolvers, selectors, store ) {
return;
}

store.dispatch(
metadataActions.startResolution( selectorName, args )
);
await fulfillResolver(
store,
mappedResolvers,
selectorName,
...args
);
store.dispatch(
metadataActions.finishResolution( selectorName, args )
);
running = true;
setTimeout( async () => {
store.dispatch(
metadataActions.startResolution( selectorName, args )
);
await fulfillResolver(
store,
mappedResolvers,
selectorName,
...args
);
store.dispatch(
metadataActions.finishResolution( selectorName, args )
);
running = false;
}, 0 );
}

fulfillSelector( ...args );
Expand Down

0 comments on commit de352f7

Please sign in to comment.