-
-
Notifications
You must be signed in to change notification settings - Fork 188
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
Field extensions #264
Field extensions #264
Conversation
78a0dc4
to
63f2551
Compare
…neous type CombineExtensions
@omnidan , I was able to add the docs, and this should be ready to merge as long as it looks good to you. It should definitely be squashed to not have all the annoying commits 😄 One thing to note, I removed some of the extraneous types like Cheers 👍 |
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.
Awesome PR and idea! Thanks for implementing field extensions. 😁
I was wondering whether we should put certain field extensions into the core redux-undo library or rather move them into a separate library/project? This would reduce the bundle size for those who do not use field extensions at all. What do you think?
I also noticed some field extensions are not documented and I think the disableWarnings
option could be an argument to the field extension functions instead of a redux-undo wide option.
Otherwise this looks great and it will solve many issues people have had with redux-undo! 🎉
return (undoableConfig) => { | ||
console.log(undoableConfig) | ||
if (!undoableConfig.disableWarnings) { | ||
console.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.
maybe we should only show this warning if we detect that the state contains one of redux-undo's field names, or an array/primitive?
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 thought about that. The issue is you would be checking the returned object for every action that was dispatched to the wrapped reducer (there is no way to check only the first time and then trust it from then on).
I thought it would be best to warn the user exactly once at initialization, no matter what the user has in their state. It should also be very clear in the documentation that this is the case (I can make it more explicit).
Thoughts?
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.
yeah, I see, that makes sense. then let's keep it as is but put the disableWarnings
option as an argument to the function. let's also separate the field extensions into a separate package.
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.
Sounds good 👌
|
||
if (!undoableConfig.disableWarnings) { | ||
console.warn( | ||
'Warning: the actionField() extension might override other state fields', |
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.
also here, should we only warn when we detect that it is overriding something?
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.
Same idea as above.
|
||
// istanbul ignore next: This will be put on hold for now... | ||
// eslint-disable-next-line no-unused-vars | ||
const nullifyFields = (fields = [], nullValue = null) => { |
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.
document these in README as well?
do you think the field extensions should be part of redux-undo core, or maybe a separate library? I don't think everyone will need it and it slightly increases the bundle size
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 had briefly mentioned in the PR description that these were WIP and would come out soon, but I realize that it is silly to leave them there. I'll remove them until they are fully implemented. 👍
As for separating them into a different package, that sounds like a good idea! They are purposely optional and, yes, not everyone needs it in their bundle (though tree-shaking is starting to mitigate the problem).
@@ -90,6 +90,8 @@ export default function undoable (reducer, rawConfig = {}) { | |||
neverSkipReducer: false, | |||
ignoreInitialState: false, | |||
syncFilter: false, | |||
extension: () => (state) => state, | |||
disableWarnings: false, |
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.
this could be an argument to the extension function instead of a redux-undo wide config
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.
We can do that.
Please check if the PR fulfills these requirements
What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
Adds a config option
extension
that allows the user to add different "field extensions." ThecombineExtensions
helper allows the user to use multiple at once.Included is the much requested
flattenState
andactionField
.What is the current behavior? (You can also link to an open issue here)
Requested in #179 and #233.
There are also WIP versions for helping with #150 and #237.
What is the new behavior?
Extensions would be added like so.
disableWarnings
disables the warnings that are logged by each field extension that describes how some state might be overridden.Extension descriptions:
Note when using flattenState: all the normal state is still there (
.past
,.index
, etc.) but the user's present state is just copied down a level.Does this PR introduce a breaking change? (What changes might users need to make in their application due to this PR?)
This should not break any existing code
Other information:
Docs still have to be updated. However, the readme probably needs a little cleanup anyways.Docs have been added