These are chat archives for canjs/canjs

20th
Aug 2018
Julian
@pYr0x
Aug 20 2018 13:09
@justinbmeyer you said that setting a default select should be in a different way, can you tell me what do you mean? :point_up: 28. Juni 2018 04:47
because i did something links this but that dont work :point_up: 18. August 2018 20:02
Justin Meyer
@justinbmeyer
Aug 20 2018 13:33
Julian, I might be able to take a look in 2hrs. I’m interviewing some folks.
Julian
@pYr0x
Aug 20 2018 13:43
alright ... no hurry.. i am still in the office
Justin Meyer
@justinbmeyer
Aug 20 2018 14:17
@Bajix plant the seed. Others might help it grow.
Justin Meyer
@justinbmeyer
Aug 20 2018 14:42
@pYr0x so, I've forgotten what you are trying to do, can you summarize it for me?
You want this.select = "all"; to be set when a promise resolves?
Justin Meyer
@justinbmeyer
Aug 20 2018 14:49
Julian
@pYr0x
Aug 20 2018 15:31
i want to fill a select dropdown with a REST API and select the first item of the list
but in this example the select will not work anymore
Kevin Phillips
@phillipskevin
Aug 20 2018 15:36
you need to also listen to when the prop is set and resolve then also
prop.listenTo(prop.lastSet, prop.resolve);
Kevin Phillips
@phillipskevin
Aug 20 2018 15:50
does that fix your issue @pYr0x ?
Julian
@pYr0x
Aug 20 2018 18:43
@phillipskevin yes this solves the problem... but is this code the corrent way to set a default value after getting the list from an API

select: {
    type: "string",
    value: function (prop) {
      prop.listenTo("data", () => {
        prop.resolve(this.data.get(0).value);
      });
      prop.listenTo(prop.lastSet, prop.resolve);
    }
  },
  data: {
    get: function (lastSet, resolve) {
      this.dataPromise.then(resolve);
    }
  },
  dataPromise: {
    get: function () {
      return Select.getList(Object.assign({}, this.apiEndpoints));
    }
  },
Julian
@pYr0x
Aug 20 2018 19:24
which one is the correct way to set data based on a promise
with set directly
data: {
  value: function (prop) {
    prop.listenTo("dataPromise", function () {
      this.dataPromise.then((response) => {
        if (response) {
          this.data = response;
        }
      });
    });
    prop.listenTo(prop.lastSet, prop.resolve);
  }
}
or with resolve
data: {
  value: function (prop) {
    prop.listenTo("dataPromise", function () {
      this.dataPromise.then((response) => {
        if (response) {
          prop.resolve(response);
        }
      });
    });
  }
}
Julian
@pYr0x
Aug 20 2018 19:30
with the first one: prop.lastSet gets set, with the second one not