当前位置: 首页>>代码示例>>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;未经允许,请勿转载。