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

can.Compute is called too many times

$
0
0
Can you explain why in this fiddle (can.Component with can.compute in scope and compute change event handler)


after attr1 is set to value 1 can.compute "comp" is called 3 times not just one?

  1. can.Component({
  2.     tag: 'test-comp',
  3.             
  4.     scope: {
  5.         init: function(){
  6.             console.log('test-comp init')
  7.         },
  8.         
  9.         comp: can.compute(function(){
  10.             var attr1 = this.attr('attr1'),
  11.             attr2 = this.attr('attr2')
  12.             console.log('comp attr1 attr2', attr1, attr2)    
  13.             return null
  14.         })
  15.     },
  16.     
  17.     events: {
  18.         '{scope} comp': function(){
  19.             
  20.         }
  21.     }
  22.     
  23. })

  24. $('body').append(can.view.mustache('<test-comp/>')())

  25. setTimeout(function(){
  26.     $('test-comp').scope().attr('attr1', 1)
  27.     
  28. })

Viewing all articles
Browse latest Browse all 3491

Trending Articles