Quantcast
Channel: JavaScriptMVC Forum
Viewing all articles
Browse latest Browse all 3491

Re : No this.element in can.Component.scope like can.Control?

$
0
0
Your scope should really be independent of elements for the most part.  For example, I often create a separate, easily unit testable Map constructor that I use as my scope.


For instance:

  1. Turnstile = can.Map.extend({
  2.   locked: true,
  3.   coin: function(){
  4.     this.attr("locked", false)
  5.   },
  6.   push: function(){
  7.     this.attr("locked", true)
  8.   }
  9. })


And then use Turnstile as your scope:


can.Component.extend({

  tag: "turnstile",

  template: "{{#if locked}}LOCKED{{else}}UNLOCKED{{/if}}"

  scope: Turnstile

})





Viewing all articles
Browse latest Browse all 3491

Trending Articles