-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Framework: Add create-selector
library for memoized selectors
#3545
Conversation
* @return {Function} Memoized selector | ||
*/ | ||
export default function createSelector( selector, getDependants = ( state ) => state ) { | ||
const memoizedSelector = memoize( selector, ( state, ...args ) => args.join() ); |
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.
maybe in dev mode, yell if any args are objects? can see this being really easy to screw up.
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.
maybe in dev mode, yell if any args are objects? can see this being really easy to screw up.
Good idea. Added in 40ef2de.
👍 Looks good to me. We'll need to be a bit careful with making sure we list all dependent state. |
f49571d
to
d3d4472
Compare
return ( state, ...args ) => args.join(); | ||
} | ||
|
||
const warn = require( 'lib/warn' ); |
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.
huh. does this actually keep these out of the prod bundle? I thought the analyzer was static...
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.
huh. does this actually keep these out of the prod bundle? I thought the analyzer was static...
In testing this theory, you're correct that it would be included in the bundle, with the caveat being if Webpack is able to determine assuredly that the require
would never be reached, i.e. if I had a module defined as:
var m;
if ( true ) {
m = require( './a' );
} else {
m = require( './b' );
}
...then Webpack is smart enough not to include the ./b
file in the bundle.
All the more reason I think we ought use DefinePlugin
and specify a __DEV__
variable, to be replaced with true
or false
and such optimizations could take effect.
@blowery : Lucky for me, we already define |
Framework: Add `create-selector` library for memoized selectors
Related: #3522
This pull request implements a new
create-selector
library for creating memoized state selectors.It seeks to be an alternative to reselect, better accommodating our patterns for retrieving values with variable arguments.
See included README.md for more information and usage
Testing instructions:
This is not included anywhere in the application, so should have no impact on existing behavior.
Ensure that included Mocha tests pass by running
make test
fromclient/lib/create-selector
./cc @gwwar , @blowery (for dependent/dependant grammar verification 😉 )