首页 > 解决方案 > 使用 Reflux Actions 等待完成多个请求

问题描述

首先,初始化应用程序。我调用了许多 Async Reflux Actions 请求:

    ExpenActions.loadAccounts();
    WareActions.load();
    ProdActions.load();
    NotifActions.load();

所有请求都是这样创建的:

import Reflux from 'reflux';

const WareActions = Reflux.createActions({

    load: { asyncResult: true },
});

    onLoad() {
        console.log("start load...")

        return yajax.get(this._prefix+'warehouse/get').then(
            Actions.load.completed, 
            Actions.load.failed);
    },

    onLoadCompleted(data) {
        console.log("completed load", data);

        this.setState({
            rows: (data.success) ? data.data : [],
            isLoaded: false
        })
    },

    onLoadFailed() {
        console.log("failed load");
    },

我可以分别等待每个请求..但是如何在所有事件完成后挂起一个事件?

Promise.all不起作用..因为WareActions.load()返回未定义...不是Promise..

标签: javascriptreactjsasynchronouspromiserefluxjs

解决方案


推荐阅读