-
-
Notifications
You must be signed in to change notification settings - Fork 15.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
WIP: Add warnMutations middleware #138
Conversation
Copying deep on every dispatch is probably not feasible unless you're building apps with small state. I can't think of another way to do this off the top of my head though. |
This is meant to be used in development only. |
This assumes |
@gaearon yes:
|
@@ -0,0 +1,54 @@ | |||
import isEqual from 'lodash/lang/isEqual'; | |||
import any from 'lodash/collection/any'; | |||
import cloneDeep from 'lodash/lang/cloneDeep'; |
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.
A recent pull request removed lodash dependency. I think it would be better to avoid using lodash
Pushed some updates: Avoiding using lodash and checking for immutable types. I'm not sure if it's a good thing to avoid using libraries that have been battle tested like lodash in spite of library size. We'll be maintaining and having to support edge cases for deep cloning or whatever we're replacing from lodash. Still, perhaps that's enough for our needs in this case, so if anyone sees something odd here or anything I'm missing let me know! I'll try to add more test cases to see I'm not missing any basic scenario |
I only think it makes sense to avoid lodash for the core stuff. Plugins (which should be in separate repos anyway) can use lodash, especially if they're dev-only. |
If/when you do use lodash, you should also require the specific module you want to use. // This
import isEqual from "lodash.isequal"
// instead of this
import isEqual from "lodash/lang/isEqual" |
@acdlite what's the reason for that? the latter option will still make the bundle require only the needed modules and no more |
This is correct AFAIK. |
True, but the first way it makes it less likely another dev will see a lodash dependecy and be tempted to import the entire library elsewhere. |
To me personally there is no difference between the two versions, except that the latter is more descriptive. If at all, the second one would be more logical to me, as people see that you are specifically importing a subset/function directly, instead of a prop from the whole lib. Sent from my iPhone
|
Think about what the corresponding Clearly this is a matter of preference, though. |
I agree it's mostly a matter of preference. The only concern I have is that But again since this particular thing is just for development, that On Saturday, June 20, 2015, Andrew Clark notifications@github.com wrote:
|
Huh, I never import the entire lodash module ¯_(ツ)_/¯ |
Not meant import, but have lodash as a dependency in package.json On Saturday, June 20, 2015, Andrew Clark notifications@github.com wrote:
|
In any case, since the argument I mentioned is not strong in this case On Saturday, June 20, 2015, Leonardo Andrés Garcia Crespo leoasis@gmail.com
|
Ok I think this is now mostly complete. We now need to decide if we'll leave it here, move it to a different repo, and if leaving it here if we should automatically add it to the default redux middleware if we detect we're in the development env (assuming |
Please can you move this to a separate repo and try to get it working with the |
@gaearon will do! Any particular name for this one you would prefer? |
@leoasis's library is here in case you are looking for it in this thread: |
@0xR thanks for adding this here |
Aims to fix #135
I've implemented the mutation warnings as a middleware, which expects to receive plain actions (should be the last in the chain or at least should be after the ones that transform the actions such as the
thunkMiddleware
).Still need to provide support for stuff like ImmutableJS but should be straight forward. Also, I'm leaving it like this so that we can discuss implementation.
We can also discuss what's the best way to handle adding this middleware by default on dev, but not in prod (and avoid including the dependencies as well).