Aurelia flux dispatch 仅在 activate 方法上调用一次
Aurelia flux dispatch only call once on activate method
不知道有没有人遇到过这个问题。
我正在使用 flux 在某些模块的 active 方法上加载内容。
就像这样:
export class ContractRate{
constructor(dispatcher){
this.dispatcher = dispatcher;
}
activate() {
this.dispatcher.dispatch('rates.get');
}
@handle('rates.changed')
ratesChanges(action, rates){
this.rates = rates;
}
}
export class Index{
constructor(dispatcher){
this.dispatcher = dispatcher;
}
@handle('rates.get')
getRates(){
//here there's some code that retrieves the rates
this.dispatcher.dispatch('rates.changed', this.rates);
}
@handle('rates.changed')
ratesChanges(action, rates){
this.rates = rates;
}
}
问题是,似乎
this.dispatcher.dispatch('rates.get');
只出现一次。
ContractRate 在选择某个选项卡时加载,这会触发启动所有事件调度的激活方法。
这在第一次执行 activate 方法时有效,下一次则无效。
我很确定会发生这种情况,因为我在 activate 方法上使用了调度程序,因为我已经将调度程序调用移到了另一个方法并且它工作得很好。
希望你们中的任何人能帮我解决这个问题。
好吧,解决方法很简单。
如果您想处理事件,请不要将处理事件的方法保留在可以停用的模块上。
就我而言,我将所有处理方法都移到了我的一个路由器之外,并将其放在了不同的模块中。
就这么简单。
不知道有没有人遇到过这个问题。 我正在使用 flux 在某些模块的 active 方法上加载内容。 就像这样:
export class ContractRate{
constructor(dispatcher){
this.dispatcher = dispatcher;
}
activate() {
this.dispatcher.dispatch('rates.get');
}
@handle('rates.changed')
ratesChanges(action, rates){
this.rates = rates;
}
}
export class Index{
constructor(dispatcher){
this.dispatcher = dispatcher;
}
@handle('rates.get')
getRates(){
//here there's some code that retrieves the rates
this.dispatcher.dispatch('rates.changed', this.rates);
}
@handle('rates.changed')
ratesChanges(action, rates){
this.rates = rates;
}
}
问题是,似乎 this.dispatcher.dispatch('rates.get'); 只出现一次。
ContractRate 在选择某个选项卡时加载,这会触发启动所有事件调度的激活方法。 这在第一次执行 activate 方法时有效,下一次则无效。
我很确定会发生这种情况,因为我在 activate 方法上使用了调度程序,因为我已经将调度程序调用移到了另一个方法并且它工作得很好。
希望你们中的任何人能帮我解决这个问题。
好吧,解决方法很简单。 如果您想处理事件,请不要将处理事件的方法保留在可以停用的模块上。
就我而言,我将所有处理方法都移到了我的一个路由器之外,并将其放在了不同的模块中。 就这么简单。