dimanche 26 juillet 2015

ES6 Set setting but "size" not changing

I am using ES6's new Set type/object and I'm running into a very odd problem where when I add an item to the set it shows up as part the <entries> but the size doesn't shift from zero:

console.log

To give a bit more context, here's the code that initially sets up the code:

selectedValues: on('init',computed('group.selected', {
  set: function(param,value) {
    return typeOf(value) === 'array' ? new Set(value) : new Set([value]);
  },
  get: function() {
    return new Set();
  }
}))

Note: this is an Ember computed property for those of you not familiar with the syntax

and here's the code that is adding/deleting elements of the set:

  if(selectedValues.has(elementId)) {
    selectedValues.delete(elementId);
  } else {
    selectedValues.add(elementId);
  }

At any point in execution I can see from the console that the item is being added and removed from the Set but the size property is not effected. At the same time if I run the same set of commands from the browser's console it does work.

For those familiar, I am using Babel via the ember-cli-babel plugin. I have tried this problem both with and without the includePolyfill option (aka, including -- or not -- Babel's browser polyfill).




Aucun commentaire:

Enregistrer un commentaire