These are chat archives for canjs/canjs

28th
May 2015
Patrick Clancy
@patrickclancy
May 28 2015 17:28
If I’m using the define plugin with a can.Map. Shouldn’t the set() function be execute with myMap.attr(’users’).push('123’)?
define: {
  users: {
    value: [],
    set: function(newValue) {
        … side effect stuff here
        return newValue;
    }
}}
Alexis Abril
@alexisabril
May 28 2015 17:33
Hey @patrickclancy, not for this example. This is because you’re not actually setting users, you’re setting users[‘someIndex’]
in this case, if it’s an empty array, .push would be akin to myMap.attr(‘users.0’, ‘123’);
however, if you did myMap.attr(‘users’, []), the setter would be called as you’d be setting the ‘users’ property directly
Justin Meyer
@justinbmeyer
May 28 2015 17:34
yeah, the define plugin doesn't work for can.List unfortunately
Patrick Clancy
@patrickclancy
May 28 2015 17:36
@alexisabril @justinbmeyer Thanks… I realized myMap.attr(‘users’, []) works. I was hoping that there was more magic there. ;-)
Alexis Abril
@alexisabril
May 28 2015 17:38
it’d be cool if it works with can.List. For that scenario, it be nice to do:
var Collection = can.List.extend({
  define: {
    '*': {
      set: function(val) {
        console.log('setting');
        return val;
      }
    }
  }
});

var c = new Collection();
c.push('abc’);