0

I have a method in a view just like following.

testMethod : function() {
   //run code
}.observes('property1')

This method can either be trigerred directly by calling or triggered by the property1 observer. Is it possible to know inside the method, which way the call is getting triggered. Thanks

thecodejack
  • 12,689
  • 10
  • 44
  • 59

2 Answers2

1

When observer is called, it receives 2 arguments: the controller object, and the observed property which has changed and triggered the observer.

So you can check it like this:

testMethod : function() {
    if(arguments.length === 2 && arguments[1] === 'property1'){
        // you're triggered by property observer
    } else {
        // triggered directly
    }
}.observes('property1')

This, of course, can be spoofed by caller..

Shimon Rachlenko
  • 5,469
  • 40
  • 51
0

I have stumbled upon this myself and have found no way to do so. I ended up doing something like this:

testMethod : function() {
   //run code
},
propertyObserver : function(){
   this.testMethod();
}.observes('property1')
mavilein
  • 11,648
  • 4
  • 43
  • 48