-
Notifications
You must be signed in to change notification settings - Fork 11
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
Clearing ES6 Stores doesn't restore the initial state #24
Comments
I'm actually using |
This is an annoying side effect of ES6 and something I'm not overly happy with. The issue with capturing the initial state is, if its mutable, you're just re-assigning the initial state to itself. Also, cloning the object has lots of issues (e.g. what happens if its a class?). I concluded that |
I would just |
I agree that |
I thought Lodash's cloning function handled most cases with objects with non-trivial prototypes. Might be worth investigating - probably we need |
What about this.state = {
user: new User(123)
} Which results in |
Hmm, and That said, isn't this going to generally break dehydration/rehydration anyway? I still think this should do the right thing in most cases - anybody who needs something special can implement |
I'm with @moretti on this one - admittedly I'm heavily biased as I work with him. Naturally, capturing the initial state and re-assigning it on clear isn't suitable due to the state possibly being mutable (or uncloneable). Unless I'm missing something, simply destroying and re-instantiating the store object is the only clear solution to this problem. This would support both ES6 and ES5 implementations (class-based or using I'm open to suggestions! |
@jimmed I see what you mean now. That makes a lot of sense. |
Hi, according to the docs,
Store.clear
should replace the state with the initial state when called.This works fine in classic mode because
Store.clear
internally callsStore.getInitialState
.However in ES6 mode
Store.getInitialState
is not defined because the state is typically initialised in the class constructor and callingStore.clear
simply sets the state to an empty object.I ended up using
getInitialState
in my ES6 stores as temporary workaround, but it seems an anti-pattern.Any thoughts on this?
The text was updated successfully, but these errors were encountered: