-
Notifications
You must be signed in to change notification settings - Fork 5
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
Logs the same object as prev and next state #3
Comments
That is not a valid action: actions: {
badAndNaiveAction(state) {
state.value = 1
return state // Oh, no!
}
} If you are doing that, then you'll only get yourself in trouble, like I presume you are describing, but correct me if I am wrong! I admit the docs should be more clear about this. Right now this is what they say:
But it could add that you should always return a new state or partial state, and not mutate the state you were given and return it. |
Yes, I was being lazy. I've already fixed the function, but I do think logger, as a developer tool, should not create confusing output especially if it seems the developer is lazy or less skilled ;) Alternatively, maybe it's worth spending a few bytes to add a check to hyperapp like this: if ( newState === oldState ) { throw Error('actions must return new state') } |
It's okay, I am lazy too sometimes! My point was that if you were use actions incorrectly, then you should do it at your own risk. But I would be happy to hear ideas about how the logger could help you if you are in a lazy mood though.
Sounds good to me. But we don't have to throw, simply skipping the update is a good compromise We won't be able to be lazy though, are you sure? 😉🤔 At any rate, I'd be happy to add those extra bytes to core. |
@naugtur if you want mutating the state in place to be an error during development, consider using freeze: https://github.com/okwolf/hyperapp-freeze |
I suggest a warning if new state===oldstate with a link to explanation why would be best |
@naugtur A warning belongs to a development build / distribution. On the other hand... the logger is not really for production use. |
My point exactly. I'm configuring my build to skip the logger next week. |
@naugtur Cool. How do you skip it? |
I'll try two options and see which I like better. More likely the latter. |
@jbucaran this sounds like something that should be configured with options. My personal preference would be off-by-default, although I wonder if on-by-default would be better for newcomers to to Hyperapp who may not know this gotcha. |
If you want to bake this into the logger, then please make it false by default. But I would prefer if the logger did not mind this. I think this kind of correctional behavior belongs in a dev build of hyperapp, not in a mixin. And about a higher-order app, that sounds interesting! |
When an action is not creating a brand new object but extending the existing one before returning, logger will log the original reference instead of a copy/deep clone. The object gets updated before it's printed to the console and both prev and next logs are identical, which is misleading.
Possible fixes:
The text was updated successfully, but these errors were encountered: