-
Notifications
You must be signed in to change notification settings - Fork 47.5k
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
Keep or Drop replaceState? #2843
Comments
On the immutability note, I've started using fluxy which uses mori internally for store states and I've started using object subtrees of the store as state in components (like a cursor) and the component listens to changes in the store under it's cursor's key array scope. Then we get It's working pretty well and I'd hate to lose this :). But at the same time if you're planning on supporting something like Immutable.Record it might be cool (fluxy is working on abstracting the immutable data structure implementation to support immutable.js). But to be honest tying React into a specific implementation of immutable data kinda defeats the purpose when it comes to modularity and so on. Maybe if there are some hooks that allow you to plugin what you use wether it is immutable.js or mori. |
A bit out of loop but, if state is I'm against whatever custom Edit: if you wanna type check |
The main place I use/see use of replaceState is when you've already done the merge, and while setState would work the same, it's also inefficient. // getInitialState: () => ({a: {b: 0}}})
incr = (o) => updates(o, {a: {b: {$apply: (x) => x + 1}}});
var state = incr(this.state);
state = incr(state);
this.replaceState(state, (state) => state.a.b === 2); This pattern tends to arise from react's inability to queue immutable updates. this.setState({a: incr(this.state.a)});
// setState is async, so this would throw out the above changes
this.setState({a: incr(this.state.a)})
// when doing async things, the final state depends on batching strategy, and unless
// batching strategy is nextTick, race conditions
asyncThing(() => {
this.setState({a: incr(this.state.a)}, (state) => state.a.b === 1 || state.a.b === 2)
});
// vs a hypothetical safe variant
this.enqueState({a: incr});
this.enqueState({a: incr});
asyncThing(() => {
this.enqueState({a: incr}, (state) => state.a.b === 3);
}); |
I've always loved that idea, but I don't think it negates the value of @brigand I feel quite confident that "inefficient" in this case is not really measurable in any real life scenario. But I could be wrong. |
Presumably an engine with hidden classes can do an optimization for
|
Closing in favor of #2843, I guess. |
Er, #3236. |
This is continuing the conversation started in #2805
We're considering dropping replaceState because ideally state should always keep a consistent signature, defined by getInitialState.
The text was updated successfully, but these errors were encountered: