Canjs uses a Model View Controller design pattern, where data is held in a Can Observable or Can Model, flow control is handled by a Can Control, and the view is created in html and Javascript with either EJS or mustache templates. We use mustache currently, because it forces us to make conditional statements outside of the template. In addition, routing is handled by a separate router controller that listens to url changes and based on them passes control to different page controllers.

We find this paradigm to be simpler to understand and implement and easier to use when multiple people are working on an application because the MVC pattern enforces separation of concerns and flow control. In other words, once person can work on a view and another can work on a controller without working on the same file and coming into conflict. Therefore, we expect each page to at a minimum have its own controller and at least one view (EJS file in our case).

Can.js currently supports one way data binding from the model to the view. In order to have a user change the model, we need to implement event listeners in the controller that add to or delete from the model, based on user input.

  • No labels