Let's say I have Article
s which are backed by Source
s. Each article has one source.
Sources have associated HTML which will be rendered on screen.
I want this HTML to be rendered only if the source changed.
App.ArticleView = Ember.View.extend({
didInsertElement: function() {
this.addObserver('controller.source.id', function() {
console.log(arguments);
renderHTML();
});
});
});
This behaves exactly as stated in the addObserver documentation, "Note that the observers are triggered any time the value is set, regardless of whether it has actually changed. Your observer should be prepared to handle that."
If setting a controller.model
of Article
A
with source 1
is followed by setting a controller.model
of Article
B
with source 1
, the observer will call the method but I want to prevent renderHTML() from happening.
The documentation mentions "Observer Methods" which I'm not sure how to put to use in this case. Its signature (function(sender, key, value, rev) { };
) looks exactly like what I need, but in my tests the arguments
to the observer method are always 0: (current view), 1: "controller.source.id"
.
How can I get the previous value of controller.source.id
, so as to determine whether to renderHTML()
or not?