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

Re : Prevent binding to attribute changes executed inside function

$
0
0
Well yes function is a member of scope for example that is passed to some child component as attribute.

Say I have function that should return some filtred items, and also I want to execute some action on this items.

  1. scope: {

  2.      filteredItems: function(){

  3.             var filtered = this.items.filter(function(){...})

  4.             // some additioal action that touches item's attributes but I don't want this changes to be handled by filteredItems
  5.             filtered.forEach(function(){...})

  6.             return filtered

  7.       }
  8. }

Actually this is solved by definining filtredItems as attribute with define.get 
  1. scope: {
  2.       define: {
  3.             fiteredItems: {
  4.                   get: function(){

  5.                         return this.items.filter(function(){...})
  6.                   }
  7.             }
  8.       }
  9. },

  10. events: {

  11.       '{scope} filteredItems': function(scope, ev, filtered){
  12.               // some additioal action 
  13.             filtered.forEach(function(){...})

  14.       }
  15. }
I just thought maybe first variant could be accomplished somehow.

Viewing all articles
Browse latest Browse all 3491

Trending Articles