-
-
Notifications
You must be signed in to change notification settings - Fork 835
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
Add typings for class component state attribute #2995
Conversation
0f153ba
to
0c89226
Compare
Are there benefits to using |
There isn't any inherent benefit, no. The reason I added this was because it's part of mithril, like attrs and lifecycle hooks. I would rather discourage setting values on the class instance itself and instead use state. IMO, it makes it clearer to understand. |
I think I agree with this. However, I'm not sure we should make this change now until we're ready to start refactoring core. Maybe we should work on this after the TS refactor? |
I wouldn't want to work on it until we start proper development on 2.0. It'd be a breaking change for extensions that hook into existing component state if we moved it all to a |
Maybe then we should include this in the 2.0 refactors? |
In my opinion, it'd be better to add it now. It's one extra thing out of the way, and something that extension developers and new core components can use to be ready for 2.0 and reduce the upgrade workload. |
Changes proposed in this pull request:
All of our class component instances have a
state
attribute which is, by default,undefined
. This is managed by Mithril itself, but we currently have no way to apply types to it within Flarum.This PR adds the ability to set typings for this attribute more easily, so that extensions can choose to store the data for their components within
this.state
more easily.We generally store component data directly on the
this
object, but this often ends up polluting the class with lots of data. Storing it understate
makes it easier to be typed, especially if data is set dynamically, and it is more friendly to developers coming from other frameworks, such as React.We might want to consider defaulting
this.state
to an empty object within our class component. This shouldn't cause any backwards-compatibility issues, but might be better in another PR.Current method:
this.state
method:Confirmed