There are couple of cases when this can be useful:
1) Property is bound to a value which is undefined, which means it doesn't get calculated in the begining, even though it's value should evaluate to something else than undefined if the bound property changed.
This is the case discussed with @tomdale about form validation, where you might want to re-calculate validations when the form is submitted before the actual values are changed. The only workaround I found here is to use an observer instead of a property, since it can be triggered manually. But this can become bloated as you need both an observer and a property which is set by the observer.
2) I want to display a value which is bound to a periodic time interval. For example postedAt which might be showed at 5 seconds ago when the page loads, but I might want to recalculate that every couple of seconds, so the page stays up to date.
One solution that comes to mind here is to have some global App.tick, and bind the property to that, and then change it on a regular basis, but I'm not sure if that's a good design.
Currently you can call propertyDidChange('postedAt') on your model which will tell any computed properties and observers to recalculate.
Having a timer do this is probably not a good idea.
With regard to point 2. Here is a handlebars helper I put together to do auto updating relative timestamps: https://gist.github.com/4553829
It is based on the code from registerBoundHelper and could probably be refactored into a generic timer based updating bound helper.
@ivanvanderbyl I would use notifyPropertyChange rather than propertyDidChange. @darthdeus it seems like this solves your issue? If not, please reopen.
Ah yes of course, was thinking about that method and wrote the other one :smile:
This is exactly what I was looking for, thanks guys :)
i know this is an old post, but thank you @wycats, notifyPropertyChange is just what i needed!! √√√
Thanks a lot.
notifyPropertyChanged doesn't force it if it hasn't changed. Could do with something that tells Ember something has changed so update the template old chap. Even if it hasn't changed.
@Benjy1979 what would the side effects be to update the template if the value hasn't changed?
Ember.js might not think the property has changed. But in fact it might have. Say if you bound to a normal javascript array and you change a field somewhere within.
You should be able to say:"Trust me Ember, it's changed. Update it"
+1
I have the same case. The user did an action which changed the relationships of a model.
But the model, doesnt represent it in its API response. Its a date dependant relationship, so it can not be easily integrated in the models payload.
I somehow need to convince the computed property, which loads the relationship, that the server data has changed.
All I can do now is adding a boolean dependant key "triggerChangeIndicator" and use toggleProperty('triggerChangeIndicator').
That is the same workaround I do sometimes,
Most helpful comment
@ivanvanderbyl I would use
notifyPropertyChangerather thanpropertyDidChange. @darthdeus it seems like this solves your issue? If not, please reopen.