You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I like this. It will encourage users to use the most direct node in the tree to set state. We will need to make this very explicit in the docs and give examples for how to turn it off. I could see it being confusing for people coming from other state management tools... Basically, we are encouraging users to be very specific with what parts of state update and to use multiple setPartialState()s instead of lazily setting a portion of the state tree once.
The shallow equals will need to handle different types. Do we compare functions? We could stringify them but it could get expensive and is not always accurate.
I think shallow equality is fairly well understood and accepted? Definitely want to call it out in the docs, but:
objects A and B are unequal if
object A has different keys than object B
any values in A !== same value in B
this means that if you have a function in state you end up testing if it's the same object in memory on both sides (same applies to objects -- anything that isn't a primitive)
Middleware will be able to add additional checks, for example:
insula-immutable - Immutable objects have an equals method on them that effectively does deep comparison
deep equality check only on specific values
for some object types (or selectors?), check if an object's id field matches on both sides
As a middleware, insula-immutable can essentially do:
if(isImmutable(a)&&isImmutable(b){returna.equals(b);// insula-immutable decides fate of the update}else{next();// rely on other middleware / insula's default shallow compare}
letting it avoid dealing with any cases where a or b are primitive values
"check state equality" should be done with a shallow compare, and allow middleware to override
The text was updated successfully, but these errors were encountered: