-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Output a warning whenever user tries to use datasets without a unique key #135
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
Conversation
src/index.js
Outdated
| const shouldWarn = !currentDatasetKeys.every(d => typeof d !== "undefined") || !nextDatasetKeys.every(d => typeof d !== "undefined"); | ||
| const newDatasets = nextDatasets.filter(d => currentDatasetKeys.indexOf(this.props.datasetKeyProvider(d)) === -1); | ||
|
|
||
| if (shouldWarn && !this.hasWarned) { |
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 believe this should only occur if you are not in a production build. :)
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.
How can I check if production vs. development?
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.
Seems like this will work unless you have a better method https://stackoverflow.com/a/25922668
|
+1 this should be merged! |
|
Wasn't sure the best way to check the enviroment. There's this method https://stackoverflow.com/a/35470995 but that seems like it will only work if the user sets the NODE_ENV enviroment variable. There's also this method https://stackoverflow.com/a/25922668 which seems a little hacky but will probably work most often. Any suggestions on how to do this would be appreciated. |
|
React itself uses NODE_ENV to check it. See invariant |
|
@jerairrest , @benmccann Took me almost a year but I re-based and added the production check. Also added some unit tests. How's it now? 🙂 |
|
@jerairrest just pinging |
After #116, if you omit the label from your dataset because you don't need it, it fails silently and all the datasets are combined into one.
This is a small PR to output a warning if a user tries to add datasets without keys, similar to how React outputs a warning when you omit a key.