2016-07-26 60 views
0

我在我的应用程序中使用RiotJSRiotControl以组件和事件处理的步骤为基础的旅程。窗体屏幕之一本质上收集到两个商店的数据。在旧金钱中,我会称之为多模型视图,并且会使用Rails之类的视图模型来处理此问题。屏幕收集客户信息和实际旅程信息,因此当提交表单时,两个不同的问题将发送到两个不同的商店。RiotControl来自多个商店的触发动作

// Store Examples 

function customerDetails() { 

    riot.observable(this); 

    this.customer = {firstName: undefined, lastName: undefined} 

    this.on('form-step:submitted', function(answers){ 
    this.customer.firstName = answers.firstName, 
    this.customer.lastName = answers.lastName 

    RiotControl.trigger('customerDetails:updated', this.customer); 
    }) 
} 

function surveyDetails() { 

    riot.observable(this); 

    this.survey = {questionOne: undefined, questionTwo: undefined} 

    this.on('form-step:submitted', function(answers){ 
    this.survey.questionOne = answers.questionOne, 
    this.survey.questionTwo = answers.questionTwo 

    RiotControl.trigger('surveyDetails:updated', this.customer); 
    }) 
} 

// In main code 

nextScreen.on('surveyDetails:updated customerDetails:updated', function(details){ 

    // I care about both of these events, but only want to execute 
    // this code once I've received the details from both stores. 

}) 

下表屏幕需要渲染之前,从两个商店的信息,所以我挣扎,看我怎么保证从两家店都更新事件被触发,安装和渲染这个画面,同时保持前来自事件处理程序的后续触发器的来自每个商店的数据。是这样的可能吗,还是我以错误的方式解决这个问题?

非常感谢

回答

0

也许你会需要它的步骤您当前所在的状态(我认为的好去处将是这些组件的父)。

因此,例如,customerDetails:updated会将currentStep更新为1,然后surveyDetails:updated会将currentStep更新为2. 然后在您的nextScreen.on中检查您是哪一步,然后移动到下一步。