@bindable changeHandler é acionado antes da conclusão das ligações
App.js
export class App {
constructor() {
this.widgets = [{ name: 'zero'}, {name: 'one'}, {name:'two'}];
this.shipment = { widget: this.widgets[1] };
}
}
App.html
<template>
<require from="./widget-picker"></require>
<require from="./some-other-component"></require>
<widget-picker widget.bind="shipment.widget" widgets.bind="widgets"></widget-picker>
<some-other-component widget.bind="shipment.widget"/>
</template>
widget-picker.js
import {bindable, bindingMode} from 'aurelia-framework';
export class WidgetPicker {
@bindable({ defaultBindingMode: bindingMode.twoWay, changeHandler: 'widgetChanged' })
widget;
@bindable widgets;
widgetChanged(widget) {
// Use an Event Aggregator to send a message to SomeOtherComponent
// to say that they should check their widget binding for updates.
}
}
widget-picker.html
<select value.bind="widget">
<option repeat.for="widget of widgets" model.bind="widget">${widget.name}</option>
</select>
O problema:o@bindable
changeHandler dispara o evento widgetChanged antes que a ligação seja atualizada paraApp.js e os seusthis.shipment.widget
.
Portanto, quando a mensagem do Agregador de Eventos sair, o valor anterior ainda será definido em `this.shipment.widget '.
Pergunta, questão:Existe uma maneira de fazer@bindable
O changeHandler espera até que todas as ligações que serão atualizadas para @bindable estejam concluídas?
Ou existe outro retorno de chamada que eu possa usar? Talvez um alterado Handler (pretérito)?
Eu tentei adicionarchange.delegate="widgetChanged"
aoselect
, esperando que odelegate
A opção tornaria mais lenta, mas ainda é acionada antes que a atualização seja totalmente lançada.