Beispiel #1
0
        /// <summary>
        /// 调度
        /// 1.这里要处理好异步任务,并且组装好事件队列
        /// 2.异步会堵塞同步方法,同一时间只有1个dispatch能执行
        /// </summary>
        async public void Dispatch(UFluxAction action)
        {
            var oldState = GetCurrentState();

            // foreach (var reducer in reducer)
            {
                var ret = reducer.IsAsyncLoad(action.ActionTag);
                if (!ret) //同步模式
                {
                    //先执行await
                    var newstate = await reducer.ExcuteAsync(action.ActionTag, action.Params, oldState);

                    //再执行普通
                    if (newstate == null)
                    {
                        newstate = reducer.Excute(action.ActionTag, action.Params, oldState);
                    }

                    //设置new state
                    SetNewState(action.ActionTag, newstate);
                }
                else //回调模式
                {
                    reducer.ExcuteByCallback(action.ActionTag, action.Params, GetCurrentState, (newState) =>
                    {
                        //设置new state
                        SetNewState(action.ActionTag, newState);
                    });
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// 调度
        /// 1.这里要处理好异步任务,并且组装好事件队列
        /// 2.异步会堵塞同步方法,同一时间只有1个dispatch能执行
        /// </summary>
        async private void Dispatch(UFluxAction action)
        {
            var executeType = reducer.GetExecuteType(action.ActionTag);

            switch (executeType)
            {
            case AReducers <S> .ExecuteTypeEnum.Synchronization:
            {
                var oldState = GetCurrentState();
                var newstate = reducer.Excute(action.ActionTag, action.Params, oldState);
                //设置new state
                SetNewState(action.ActionTag, newstate);
            }
            break;

            case AReducers <S> .ExecuteTypeEnum.Async:
            {
                var oldState = GetCurrentState();
                var newstate = await reducer.ExcuteAsync(action.ActionTag, action.Params, oldState);

                //设置new state
                SetNewState(action.ActionTag, newstate);
            }
            break;

            case AReducers <S> .ExecuteTypeEnum.Callback:
            {
                reducer.ExcuteByCallback(action.ActionTag, action.Params, GetCurrentState, (newState) =>
                    {
                        //设置new state
                        SetNewState(action.ActionTag, newState);
                    });
            }
            break;
            }
        }