當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript form.reducer.factory類代碼示例

本文整理匯總了TypeScript中app/store/forms/form.reducer.factory的典型用法代碼示例。如果您正苦於以下問題:TypeScript reducer.factory類的具體用法?TypeScript reducer.factory怎麽用?TypeScript reducer.factory使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了reducer.factory類的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: describe

describe('Form reducer factory', () => {

    const config: FormReducerOptions<ExtendedFormState> = {
        show: 'show',
        hide: 'hide',
        toggle: 'toggle',
        request: 'request',
        success: 'success',
        failure: 'failure',
        extras: [{
            types: 'setExtraProp',
            func: (state, action) => assign(state, { extraProp: (action as any).payload })
        }],
        successMessage: 'success!'
    };

    interface ExtendedFormState extends FormState {
        extraProp: any;
    }

    const reducer = formReducer<ExtendedFormState>(config);

    let oldState: ExtendedFormState;

    beforeEach(() => {
        oldState = assignDeep(FormStates.Default as any, { extraProp: 'hello' });
    });

    shouldNotAlterStateOnUnknownAction(reducer);

    it('applies the form visibility WHEN show is called', () => {
        oldState.showForm = false;
        const newState = reducer(oldState, action(config.show as string));
        expect(newState).toEqual(assign(oldState, { showForm: true }));
    });

    it('applies the form visibility WHEN hide is called', () => {
        oldState.showForm = true;
        const newState = reducer(oldState, action(config.hide as string));
        expect(newState).toEqual(assign(oldState, { showForm: false }));
    });

    it('applies the form visibility WHEN toggle is called', () => {
        oldState.showForm = false;
        let newState = reducer(oldState, action(config.toggle as string));
        expect(newState).toEqual(assign(oldState, { showForm: true }));
        newState = reducer(newState, action(config.toggle as string));
        expect(newState).toEqual(assign(oldState, { showForm: false }));
    });

    it('applies the requesting state WHEN request is called', () => {
        const newState = reducer(oldState, action(config.request as string));
        expect(newState).toEqual(assign(oldState, FormStates.Requesting));
    });

    it('applies the success state WHEN success is called', () => {
        const newState = reducer(oldState, action(config.success as string));
        expect(newState).toEqual(assign(oldState, FormStates.Success(config.successMessage)));
    });

    it('applies the failure state WHEN failure is called', () => {
        const newState = reducer(oldState, action(config.failure as string));
        expect(newState).toEqual(assign(oldState, FormStates.Failure(getErrorMessage(undefined))));
    });

    it('Runs custom cases WHEN they are passed', () => {
        const newState = reducer(oldState, action('setExtraProp', '1234'));
        expect(newState).toEqual(assign(oldState, { extraProp: '1234' }));
    });
});
開發者ID:mikule1,項目名稱:epool.eu,代碼行數:70,代碼來源:form.reducer.factory.spec.ts

示例2: resendEmailVerificationReducer

export function resendEmailVerificationReducer(state: FormState,  action: Action) {
    return formReducer({
        request: ResendEmailVerificationActionTypes.Resend,
        failure: ResendEmailVerificationActionTypes.Failure,
        success: ResendEmailVerificationActionTypes.Success,
        successMessage: Messages.ApiResponse.SendVerificationEmailSuccess,
    })(state, action);
}
開發者ID:mikule1,項目名稱:epool.eu,代碼行數:8,代碼來源:resendEmailVerification.reducer.ts

示例3: updateEmailReducer

export function updateEmailReducer(state: FormState, action: Action) {
    return formReducer({
        toggle: UpdateEmailActionTypes.ToggleForm,
        request: UpdateEmailActionTypes.Update,
        success: UpdateEmailActionTypes.Success,
        failure: UpdateEmailActionTypes.Failure,
        successMessage: Messages.ApiResponse.UpdateEmailSuccess,
    })(state, action);
}
開發者ID:mikule1,項目名稱:epool.eu,代碼行數:9,代碼來源:updateEmail.reducer.ts

示例4: resetPasswordFormReducer

export function resetPasswordFormReducer(
    state: FormState,
    action: Action
): FormState {
    return formReducer({
        request: ResetPasswordFormActionTypes.Reset,
        failure: ResetPasswordFormActionTypes.Failure,
        success: ResetPasswordFormActionTypes.Success,
    })(state, action);
}
開發者ID:mikule1,項目名稱:epool.eu,代碼行數:10,代碼來源:resetPasswordForm.reducer.ts

示例5: logInReducer

export function logInReducer(
    state: FormState,
    action: LogInActions.LogInAction
): FormState {
    return formReducer({
        show: LogInActionTypes.ShowModal,
        hide: LogInActionTypes.HideModal,
        request: LogInActionTypes.LogIn,
        success: LogInActionTypes.Success,
        failure: LogInActionTypes.Failure,
    })(state, action);
};
開發者ID:mikule1,項目名稱:epool.eu,代碼行數:12,代碼來源:logIn.reducer.ts

示例6: updatePasswordReducer

export function updatePasswordReducer(
    state: FormState,
    action: Action
): FormState {
    return formReducer({
        toggle: UpdatePasswordActionTypes.ToggleForm,
        request: UpdatePasswordActionTypes.Update,
        failure: UpdatePasswordActionTypes.Failure,
        success: UpdatePasswordActionTypes.Success,
        successMessage: Messages.ApiResponse.UpdatePasswordSuccess,
        failureMessage: Messages.ApiResponse.ServerError,
    })(state, action);
}
開發者ID:mikule1,項目名稱:epool.eu,代碼行數:13,代碼來源:updatePassword.reducer.ts

示例7: signUpFormReducer

export function signUpFormReducer(state: FormState, action: Action): FormState {
    return formReducer({
        request: SignUpFormActionTypes.SignUp,
        failure: SignUpFormActionTypes.Failure,
    })(state, action);
}
開發者ID:mikule1,項目名稱:epool.eu,代碼行數:6,代碼來源:signUpForm.reducer.ts


注:本文中的app/store/forms/form.reducer.factory類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。