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
Crazy question: Change state API? #158
Comments
Yes, I love it. I agree with all the points you have raised. Other Flux stores don't have this issue as they force users to implement their own public methods, whereas alt relies on It's a yes from me. |
👍 |
* insert traditional thumbsup + sparkle * 👍 ✨ |
The only backwards compatible thing I think of is if this.state is undefined then use the instance properties over this.state Sigh... oh breaking changes.... maybe think of other breaking changes at the same time so you can do a major version bump? |
Makes sense to me. I also like the idea of adopting a getInitialState() {
return {
count: 0,
foo: 'bar',
};
} rather than setting constructor() {
this.state = {
count: 0,
foo: 'bar',
};
} I've been adopting this pattern in my Alt stores. |
Take a look at http://babeljs.io/blog/2015/03/31/5.0.0/ You can now set instance properties in a class: class Store {
state = { count: 0 };
} |
@spikebrehm React 0.13 lets you set state directly in the constructor and you don't use getInitialState any more AFAIK.
Found the answer here: https://gist.github.com/jeffmo/054df782c05639da2adb It's a Stage 0 proposal so that's good but I wouldn't use it just yet since it may change drastically before it ships. |
Nice, but is 'backwards compatible' really needed ? If warnings and migration tool will be provided, this option is useless, in my opinion :) |
Backwards compatible for the interim. |
I don't have a strong preference with this change, though I think the ability to more easily have "private" instance variables regardless of how we do it is a good feature. Despite my lack of a strong preference, I do think this brings up an even bigger issue. The issue is not just moving the data to a I am curious if anyone is using alt without React as well as people's thoughts about how much alt should cater to React. I would like to try to keep alt flexible such that it can be used without React (even if it's API ends up being similar to React), but I think it is a worthwhile discussion to figure out how much alt should assume. |
I'm not as much against this change as I just like the current one better. Here's some pseudo-random thoughts this raised:
Anyway, my 0.02 EUR. :) |
Killing this in lieu of #173 |
Do people like managing state through the instance properties or should we adopt a React 0.13-like API where state is set on a
state
property?Now:
React 0.13-like
I initially went with the instance properties approach because back in the old days of writing JavaScript where we'd have data stores we would create them as a function and constructor and then keep the state as instance properties. I felt that just changing an instance property was familiar enough to everyone and had less boilerplate.
I'm considering this new change because of a few things:
Parity with React.
Although alt prides itself on not being tied down to React, lets face it, Flux and React are like Peanut Butter and Jelly. Having the same API would make things smoother.
Private instance variables.
Currently you can have your private instance variables, but you'll have to use semi-private Symbols or wait for TC-39 to add language features to add private state to a class. By having this change anything not specified in
state
is private which can be nice.Stores are automatically serializable so with
state
you can define what is serialized right from the start.This is a big reason. Say for example you're using something like firebase.
this will throw an error because these properties are not serializable.
The current solution? To either explicitly specify what is serializable via lifecycle methods, or use symbols to store that data. While this is nice and explicit I think we can remove this boilerplate entirely.
Cons of this change:
Proposal for migrating to this:
The text was updated successfully, but these errors were encountered: