1.  Defining can conrtollers:

var MyConstructor = can.Control({object fields})  creates a constructor that can be new'd to create the actual controller.
{object fields} contains data fields and functions for the controller.
The special function init() is called when the consctrctor is new'd

A function of the form "<event name>": ... defines an event listener to be attached to the associateddiv when the controller is created.

The special form "li <event name>":... will attach the listener individually to every list element in the div. This is so the function may use the current element to resolve which entry the user is interracting with

2.  Instantiating controllers

Controllers shoudl be instantiated in the document ready callback.  You instatiate then by calling

new <constructor>('#<div name to attach to>', { <parameters> })

<parameters> is available inside the init: function as this.options 

You should use parameters to pass through any models for view construction

3. Instantiating view

Views should be instantiated in the controller init: function and are created by calling

can.view(<path to ejs file>, {<parameters>]})

The view shoudl be attached to the contoller's element at

this.element.html

4.  Creating Observables

An observable can be created by using new can.Observe({<data fields>})

The observable should be passed through in a parameter in the can.view() call for use by the ejs code

  • No labels