@chasenlehara a unit-test failed because route.start()
doesn’t get called inside the test. I fixed it like this:
updateRoute(newRoute) {
route.data && route.data.assign && route.data.assign(newRoute);
}
The updateRoute
fn gets called inside a setter of a more global state obj.
selectedItem: {
set(newVal, resolve) {
resolve(newVal);
this.updateRoute({item: newVal.id});
}
}
value
property definitionselect: {
value({ resolve, listenTo, lastSet }) {
// when `select` is set, resolve with the new value
listenTo(lastSet, resolve);
// when `dataPromise` is set, reset to "all"
listenTo("dataPromise", () => {
resolve("all");
});
// resolve with the default value
resolve("all");
}
}
select
is all defined in one place
getList
returns a Promise when using can-connect
if that's what you're asking about
listenTo
when they get resolved
dataPromise: {
get: function () { // don't use resolve for the promise
return Select.getList({candidate: this.apiEndpoint});
}
},
data: {
get: function (lastSet, resolve) {
this.dataPromise.then(resolve):
}
}
listenTo("data", () => {})
data
is set with resolve
when the promise resolves
data
// don't use resolve for the promise
?
Why are you using theresolve
based getter but not usingresolve
?
get: function( lastSet, resolve )
resolve
Select.getList({candidate: this.apiEndpoint}).then(resolve)
data: {
get: function (lastSet, resolve) {
this.dataPromise.then(resolve):
}
}
return
resolve
dataPromise
in a stache file with isResolved
and the data
for to have the real data
dataPromise.value
in the template
value
in other places in your viewModel, that won't work for you