Skip to content

Commit

Permalink
Move the status computation inside the enriched selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
adamziel committed Feb 15, 2022
1 parent e7ac34e commit 2d5e270
Showing 1 changed file with 5 additions and 25 deletions.
30 changes: 5 additions & 25 deletions packages/core-data/src/hooks/use-query-select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,28 +72,10 @@ interface QuerySelectResponse {
* @return {QuerySelectResponse} Queried data.
*/
export default function __experimentalUseQuerySelect( mapQuerySelect, deps ) {
const { data, isResolving, hasResolved, ...rest } = useSelect(
( select, registry ) => {
const resolve = ( store ) => enrichSelectors( select( store ) );
return mapQuerySelect( resolve, registry );
},
deps
);

let status;
if ( isResolving ) {
status = Status.Resolving;
} else if ( hasResolved ) {
if ( data ) {
status = Status.Success;
} else {
status = Status.Error;
}
} else {
status = Status.Idle;
}

return { data, isResolving, hasResolved, status, ...rest };
return useSelect( ( select, registry ) => {
const resolve = ( store ) => enrichSelectors( select( store ) );
return mapQuerySelect( resolve, registry );
}, deps );
}

type QuerySelector = ( ...args ) => QuerySelectResponse;
Expand Down Expand Up @@ -140,9 +122,7 @@ const enrichSelectors = memoize( ( selectors ) => {
data,
status,
isResolving,
hasResolved:
! isResolving &&
hasFinishedResolution( selectorName, args ),
hasResolved,
};
},
} );
Expand Down

0 comments on commit 2d5e270

Please sign in to comment.