Exemple #1
0
    public void Dispatch(StoreActionContainer action)
    {
        isDispatching = true;

        // call provider on action with state to compute next state
        state = provider.Provide(state, action);
        ++state.stateId;

        isDispatching = false;

        if (Logging)
        {
            var c = "orange";
            if (action.type.ToString().Contains("Success"))
            {
                c = "lime";
            }
            else if (action.type.ToString().Contains("Failed"))
            {
                c = "red";
            }

            Debug.Log(string.Format("<color=white>ActionType</color>: <color={0}>{1}</color>\n" +
                                    "<color=yellow>{2}</color> <color=white>State ID</color>: <color=yellow>{3}</color>\n{4}",
                                    c, action.type, state.GetType(), state.stateId, state));
        }
        // inform listeners of changes
        onStateChanged(state);
    }
Exemple #2
0
    public override UserState Provide(UserState state, StoreActionContainer action)
    {
        UserState newState = base.Provide(state, action);


        var actionPayload = (UserActions.ResponseData)action.data;

        // Compute the next state using actionPayload
        // use action.data to fill values for next state
        switch (action.type)
        {
        case StoreActionType.LoginRequest:
            newState.isLoading = true;
            newState.message   = actionPayload.message;
            break;

        case StoreActionType.LoginFailed:
            newState.isLoading = false;
            newState.message   = actionPayload.message;
            break;

        case StoreActionType.LoginSuccess:
            newState.isAuthed    = true;
            newState.isLoading   = false;
            newState.currentUser = actionPayload.user;
            newState.isGuest     = actionPayload.user.isGuest;
            newState.message     = actionPayload.message;
            break;

        case StoreActionType.RegisterRequest:
        case StoreActionType.RegisterFailed:
        case StoreActionType.RegisterSuccess:
        default:
            break;
        }

        return(newState);
    }
Exemple #3
0
 /// <summary>
 /// Provide the next state from current State and Action.
 /// Set new state for each action type you defined in StoreActionTypes
 /// </summary>
 /// <param name="state">State.</param>
 /// <param name="action">Action.</param>
 public virtual TState Provide(TState state, StoreActionContainer action)
 {
     // Make a deep clone of the state object
     return(Extentions.DeepClone <TState>(state));
 }
Exemple #4
0
 protected void Dispatch(StoreActionContainer container)
 {
     _store.Dispatch(container);
 }