javascriptcanjscanjs-controlcanjs-map

Understanding Canjs Control sample


Am looking at the Canjs Sample for Control.

TaskStriker = can.Control({
    "{task} completed": function(){
        this.update();
    },
    update: function(){
        if ( this.options.task.completed ) {
            this.element.addClass( 'strike' );
        } else {
            this.element.removeClass( 'strike' );
        }
    }
});
var taskstriker = new TaskStriker({ 
    task: new Task({ completed: 'true' }) 
});

In this case what is the Task object exactly?. I tried creating the Task with the can.Construct but it is not triggering the update function when value is changed.

Can some one please explain a bit on this?.


Solution

  • can.Construct does not implement observable properties.

    The task object will be a can.Map (http://canjs.com/docs/can.Map.html) or a can.Model (http://canjs.com/docs/can.Model.html). With those two you are able to observe changes on the object and thus trigger the update code.