-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce the concept of registry selectors #13662
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** | ||
* Mark a function as a registry selector. | ||
* | ||
* @param {function} registrySelector Function receiving a registry object and returning a state selector. | ||
* | ||
* @return {function} marked registry selector. | ||
*/ | ||
export function createRegistrySelector( registrySelector ) { | ||
registrySelector.isRegistrySelector = true; | ||
|
||
return registrySelector; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ import createResolversCacheMiddleware from './resolvers-cache-middleware'; | |
* | ||
* @param {string} key Identifying string used for namespace and redex dev tools. | ||
* @param {Object} options Contains reducer, actions, selectors, and resolvers. | ||
* @param {Object} registry Temporary registry reference, required for namespace updates. | ||
* @param {Object} registry registry reference. | ||
* | ||
* @return {Object} Store Object. | ||
*/ | ||
|
@@ -32,7 +32,7 @@ export default function createNamespace( key, options, registry ) { | |
actions = mapActions( options.actions, store ); | ||
} | ||
if ( options.selectors ) { | ||
selectors = mapSelectors( options.selectors, store ); | ||
selectors = mapSelectors( options.selectors, store, registry ); | ||
} | ||
if ( options.resolvers ) { | ||
const fulfillment = getCoreDataFulfillment( registry, key ); | ||
|
@@ -100,10 +100,14 @@ function createReduxStore( reducer, key, registry ) { | |
* public facing API. Selectors will get passed the | ||
* state as first argument. | ||
* @param {Object} store The redux store to which the selectors should be mapped. | ||
* @param {Object} registry registry reference. | ||
* | ||
* @return {Object} Selectors mapped to the redux store provided. | ||
*/ | ||
function mapSelectors( selectors, store ) { | ||
const createStateSelector = ( selector ) => function runSelector() { | ||
function mapSelectors( selectors, store, registry ) { | ||
const createStateSelector = ( registeredSelector ) => function runSelector() { | ||
const selector = registeredSelector.isRegistrySelector ? registeredSelector( registry ) : registeredSelector; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While the logic here is fairly trivial, Is it possible to assign this once when There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, I originally wanted to implement this feature regardless of the store implementation (outside namespace-store) but it means the computation is done on each select so I moved it here to solve the issue but it seems like I didn't :P I just thought I did. I'll follow-up |
||
|
||
// This function is an optimized implementation of: | ||
// | ||
// selector( store.getState(), ...arguments ) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: