-
-
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
this.$()
returns undefined in didInsertElement
hook with Ember 1.7.0
#5452
Comments
@herom it can be |
I agree with @gdub22, this is likely due to Closing for now, but I'm happy to reopen with a JSBin reproducing the error. |
Thanks a lot @gdub22, if I remove In my case, I have to observe the |
@herom you should make a computed property for the style, and then use bindAttr or something to bind it to the attribute. You will never have this problem again. Observers are really low level, and require you to very careful. |
cssInfo: function () {
// do something dynamic to set value..
return dynamicClassName;
}.property() <div {{bind-attr class='view.cssInfo'}}>
<!-- something here -->
</div> |
@rwjblue I created 2 jsbin examples - only diverging by their used Ember versions. and here (breaking) with Ember I know that the example is somewhat silly, but it illustrates the issue 😄 @stefanpenner I'll look into your suggested solution. The problem will just be that my resolved |
@herom should be able to do |
|
@knownasilya doesn't appear to be for me (when removing the observer) |
@stefanpenner so should it return the correct value when doing |
Seems to be due to the change in Ember.computed.alias (modified in 1.7.0) Reference: #5120 |
@gdub22 👍 |
thanks for taking the time to look into the code @gdub22 but I always thought that cssInfo: function() {
return this.get('controller.cssInfo');
}.property('controller.cssInfo'), so I can do just cssInfo: Ember.computed.alias('controller.cssInfo') to achieve the same with less boilerplate code? This seems like a regression to me, as I would have to produce the above code to have a workaround to what I had already achieved by using |
@herom yea that's the idea. Just did that to try and find the root cause |
shit is AliasDescriptor in 1.7 ? I thought it wasn't landing till 1.8 #5289 is my WIP to fix it.. (although I don't know if ^^ is a bug or actually expected behaviour) |
Im am fairly certain #5289 will address this. Bah i thought AliasDescriptor was going to be part of the 1.8 release, but I suppose bugfix beta means beta... |
thanks for reopening and explanation @stefanpenner - seems like I'll stay at @gdub22 thanks for investigation 👍 |
@herom my above suggestions of using bindings + cp's is still a much better solution then using an observer. Remember you want data to flow based on consumption not based on churn. Basically you want the template to pull the data from the rest of the system, not manually push data. That being said, we can use this issue to track for now, because it does provide an example manifestation of the problem. |
@stefanpenner I see. So if the suggested way is to use bindings and computed properties I'll try and see what I can do 😃 |
@herom correct, observers are pretty low level. CP's and bindings are typically the more user friendly way of doing things. |
It is not the on('didInsertElement') hook that is firing in this case, it is the .observes('cssInfo'), and the goal of alias change is that should behave identical to observes('controller.cssInfo'). @herom you should not have observers in views that don't check that when the property changes that the view is actually in DOM, if the view does not have element, then @stefanpenner the above behavior won't be fixed by #5289 because the target of the alias isn't lazy, the alias was adding laziness. The idea of #5289 is to ensure that get/set/observes has the identical behavior on the alias as the target. This particular change is intentional. Before this change, it worked for you, but having observers in a view that update DOM and do not guard against it not being in DOM has always been a fragile thing to do. |
@krisselden thanks for the explanation - in the meanwhile I came around this issue by wrapping my code in a |
I have a
view
which has a method declared as follows:While this code works with Ember up to
v1.6.1
without any problems, inv1.7.0
this.$()
resolves toundefined
and therefore gives me the following error:The text was updated successfully, but these errors were encountered: