本文整理汇总了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' }));
});
});
示例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);
}
示例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);
}
示例4: resetPasswordFormReducer
export function resetPasswordFormReducer(
state: FormState,
action: Action
): FormState {
return formReducer({
request: ResetPasswordFormActionTypes.Reset,
failure: ResetPasswordFormActionTypes.Failure,
success: ResetPasswordFormActionTypes.Success,
})(state, action);
}
示例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);
};
示例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);
}
示例7: signUpFormReducer
export function signUpFormReducer(state: FormState, action: Action): FormState {
return formReducer({
request: SignUpFormActionTypes.SignUp,
failure: SignUpFormActionTypes.Failure,
})(state, action);
}