-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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 init flag to observers #1205
Comments
+1 . 90% of the time I implement Ember.Object.extend({
init: function() {
this._super();
this._somethingDidChange();
this._somethingElseDidChange();
}
}); |
+1 same as @workmanw |
👍 |
I think this would answer to http://stackoverflow.com/questions/11412550/observer-are-not-called-on-create/11526098#11526098 |
🙌 |
@sly7-7 it does! 👍 |
👎 I know this was discussed some with @tomhuda, though I'm not sure what the conclusion was. For my part, it's not at all obvious what this function would do. I don't see any major burden in putting things in the |
I agree the naming is confusing. Perhaps |
If we do anything with this, it should be after we decide on whether we alter the behavior of create. |
I do think it would be simpler if the super() call weren't there, if there was a postInit() hook or the current init() becomes _init() so init() doesn't need super called. I still think people forget to think about init when creating observers. |
I'm not sure what the proposed alteration to Ember.Object.extend({
init: function() {
this._super();
this._somethingDidChange();
}
/** VS **/
_somethingDidChange: function() {
}.observes('something').onInit()
}); I think |
@workmanw The proposed change to create is to have it behave more like |
@wagenet that proposal was made also with the suggestion the object not fire observers on init. If setProperties from create() caused observers you would still need to manually init for extend, undefined -> defined would still not be consistently a change.
|
@kselden, are your thoughts on this still the same? |
if @kselden's thoughts are the same, we should make sure our use of `autoinit is consistent. Then the recent change: |
If this is desired functionality, please assign me and I will implement. Otherwise, let's close this since it has been hanging out for 9 months. I like this feature and would like to see it added. |
oh the world of open source, being able to assign tasks to your CTO. 👍 Luke you have been assigned! |
@lukemelia Are you going to do this? |
👍 |
Well, I thought that observers already did that: being fired after creation. I've found this issue after creating a complex component and observing its So +1 from me. Except that I don't think we need the flag, it should be the default behavior. |
This functionality is provided for in PR #3155, in a more general way. If that PR is merged, you can do: Ember.Object.extend({
selectionDidChange: function() {
// this method will be called when the object is created, as well as when selections changes
}.observes('selection').on('didInit')
}); We can easily sugar that to |
@guilhermeaiolfi, observers are NOT fired after creation. If you want to ensure that they are, you need to call them from the init hook. |
@wagenet I know that now. I was saying exactly that I think it SHOULD be fired after creation. I mean, only if the creation of that object sets the observed property (directly or by bindings). |
🙌 |
Includes the following bugfixes: * [#1209](glimmerjs/glimmer-vm#1209) Ensure `<output form="some-value">` works properly * [#1205](glimmerjs/glimmer-vm#1205) Ensure `@tracked` assertion can be made a deprecation * [#1204](glimmerjs/glimmer-vm#1204) Ensure `loc` is populated by `build ers.element(...)` Changelog here: https://github.com/glimmerjs/glimmer-vm/releases/tag/v0.66.1
Includes the following bugfixes: * [#1209](glimmerjs/glimmer-vm#1209) Ensure `<output form="some-value">` works properly * [#1205](glimmerjs/glimmer-vm#1205) Ensure `@tracked` assertion can be made a deprecation Changelog here: https://github.com/glimmerjs/glimmer-vm/releases/tag/v0.65.1
Includes the following bugfixes: * [#1209](glimmerjs/glimmer-vm#1209) Ensure `<output form="some-value">` works properly * [#1205](glimmerjs/glimmer-vm#1205) Ensure `@tracked` assertion can be made a deprecation Changelog here: https://github.com/glimmerjs/glimmer-vm/releases/tag/v0.62.5
Includes the following bugfixes: * [emberjs#1209](glimmerjs/glimmer-vm#1209) Ensure `<output form="some-value">` works properly * [emberjs#1205](glimmerjs/glimmer-vm#1205) Ensure `@tracked` assertion can be made a deprecation * [emberjs#1204](glimmerjs/glimmer-vm#1204) Ensure `loc` is populated by `build ers.element(...)` Changelog here: https://github.com/glimmerjs/glimmer-vm/releases/tag/v0.66.1
Add a flag to indicate an observer function should be called on init.
The text was updated successfully, but these errors were encountered: