delegate

  • function
can/observe/delegate
 

observe.delegate( selector, event, handler )

delegate( selector, event, handler(ev,newVal,oldVal,from) ) listen for changes in a child attribute from the parent. The child attribute does not have to exist.

// create an observable
var observe = new can.Observe({
  foo : {
    bar : "Hello World"
  }
})

//listen to changes on a property
observe.delegate("foo.bar","change", function(ev, prop, how, newVal, oldVal){
  // foo.bar has been added, set, or removed
  this //-> 
});

// change the property
observe.attr('foo.bar',"Goodbye Cruel World")

Parameters

  1. selector {String}

    The attributes you want to listen for changes in.

    Selector should be the property or property names of the element you are searching. Examples:

    "name" - listens to the "name" property changing
    "name, address" - listens to "name" or "address" changing
    "name address" - listens to "name" or "address" changing
    "address.*" - listens to property directly in address
    "address.**" - listens to any property change in address
    "foo=bar" - listens when foo is "bar"
    
  2. event {String}

    The event name. One of ("set","add","remove","change")

  3. handler {function(ev, newVal, oldVal, prop)}

    The callback handler called with:

    • newVal - the new value set on the observe
    • oldVal - the old value set on the observe
    • prop - the prop name that was changed

Returns

{can.Observe}

the observe for chaining