-
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
Error checking in select API #4901
Error checking in select API #4901
Conversation
Noting that I'd like to explore assigning selector functions into an object produced by the |
I wasn't aware that the current api interface was still open for changes. I would like to point out, although it isn't pretty, the changes I made to the tests will allow for more consistent testing. |
console.error( `Invalid selector called, with name "${ selectorName }" for reducer "${ reducerKey }".` + | ||
' Make sure the reducerName and selectorName are correct!' ); | ||
return undefined; | ||
} |
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.
Should we add the same check line 103 or maybe reuse the same function?
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.
Fixed.
data/test/index.js
Outdated
console.error = jest.fn( () => {} ); | ||
|
||
expect( select( 'reducer1', 'selector1' ) ).toBeUndefined(); | ||
expect( console.error ).toHaveBeenCalled(); |
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.
Should we use https://github.com/WordPress/packages/tree/master/packages/jest-console instead?
@@ -100,10 +100,6 @@ export const query = ( mapSelectorsToProps ) => ( WrappedComponent ) => { | |||
}; | |||
|
|||
return connectWithStore( ( state, ownProps ) => { | |||
const select = ( key, selectorName, ...args ) => { | |||
return selectors[ key ][ selectorName ]( state[ key ], ...args ); |
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.
I just noticed that #4823 broke this line, because getState()
is not called on state[ key ]
.
Is it still relevant? There were a few major changes in the |
By the way, we discussed that it might be a good idea to add some mechanism to prevent components to explode when |
We could always add a Line 278 in 85cd6f5
Line 333 in 85cd6f5
|
Yes, totally on board with the idea 💯 Yes, let's rename as suggested 👍 |
By the way it, would be a good idea to have a helper similar to |
Description
Updated select function to print an error when the called selector does not exist.
The reason I created this PR is because I want to make sure that plugins using the Gutenberg API will not interupt the javascript execution as much as possible. I also believe all other public APIs should have some error checking.
How Has This Been Tested?
Created unit tests and tested the select API in the browser.
Also improved unit tests to reload the
data/index.js
module for each test, so all module globals are reset, ensuring a clean test environement.Screenshots (jpeg or gifs if applicable):
Types of changes
Improvement.
Checklist: