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

Re : can.Compute is called too many times

$
0
0
Well I use this code:

  1.         comp: can.compute(function(){
  2.             var attr1 = this.attr('attr1'),
  3.             attr2 = this.attr('attr2')
  4.             console.log('comp attr1 attr2', attr1, attr2)    
  5.             return attr1 + att2
  6.         })
to get updated value when attr1 and att2 are updated, then I want to place this value to some scope attribute.

To do this I handle compute change in events

  1.     events: {
  2.         '{scope} comp': function(scope, ev, comp){
  3.             this.attr('compAttr', comp)
  4.         }
  5.     }

I could also do this with events, but I don't like such approach, esp when there are more then two "base" attributes (attr1 and attr2).

  1.     events: {
  2.       setCompAttr: function(scope){
  3.             this.attr('compAttr', scop.attr1 + scope.attr2)
  4.       }  
  5.       '{scope} attr1': 'setCompAttr',
  6.       '{scope} attr2':  'setCompAttr'
  7.     }
Is there any other way to complete this besides my first option (with compute and event handler for it)? 

Viewing all articles
Browse latest Browse all 3491

Trending Articles