mardi 18 octobre 2016

Ember Object as no setters nor getters

I am working on an Ember 2.7 application and have a little issue. I have a component pulling attributes from a service and then displays them in its views as they get updated. Here is the bit of the actual code (I know this code makes no sense in terms of purpose but it's not the point) :

component.js : this is the component that pulls and display the attributes. This component calls methods from the service providing datas that are pretty much the same (2 arrays)

export

default Ember.Component.extend({
  init() {
    this._super(...arguments);
    this.set('xlsxInput', this.get('newUser').getXlsxInput());
    this.set('bulkNewUsers', this.get('newUser').getBulkNewUsers());
  },
  newUser: Ember.inject.service(),

  actions: {

    processCsvInput() {
      let arrayedCsv = csvToArray.compute(this.get('csvInput'));
      console.log("processCsvInput:", arrayedCsv);
      this.get('newUser').populateBulkNewUsers(arrayedCsv);
      this.get('newUser').setXlsNewUsers(arrayedCsv);
    },
    ...

service.js : this is the service that provides the attributes and methods

var emptyNewUser = Ember.Object.extend({
  init() {
    this._super();
  },

  visible: true
});

export default Ember.Service.extend({

  users: Ember.inject.service(),

  bulkNewUsers: [],
  xlsxInput: [],

  arrayToArObj(src, data, _that) {
    _that.get(src).arrayContentWillChange(0, null, data.length);
    var buffer = _that.get(src);
    data.forEach(function(user){
      buffer.push(emptyNewUser.create({
        firstname: user[0],
        lastname: user[1],
        email: user[2]
      }));
    });
    _that.set(src, buffer);
    _that.get(src).arrayContentDidChange();
  },
  populateBulkNewUsers(bulkArray) {
    console.log("empty bulk", this.get('bulkNewUsers'));
    this.get('arrayToArObj')('bulkNewUsers', bulkArray, this);
  },
  setXlsNewUsers(incomingArray) {
    console.log("empty xls", this.get('xlsxInput'));
    this.get('arrayToArObj')('xlsxInput', incomingArray, this);
  },
  ...

So both bulkNewUsers and xlsxInput change after going through the method arrayToArObj() but one gets updated in the component (bulkNewUsers), the other doesn't.

By looking closer to the attributes by console.logging them both I noticed that bulkNewUsers has getters and setters for each of the attributes of its objects, although xlsxInput doesn't have any getters not setters, its objects only have the three string properties. I assume the fact that the component can't pull xslxInputs comes from those getters and setters missing.

Would you know what I have done wrong ?

Thank you !




Aucun commentaire:

Enregistrer un commentaire