Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const INITIAL_STATE = createFormGroupState(FORM_ID, {
userName: '',
createAccount: true,
password: {
password: '',
confirmPassword: '',
},
sex: '',
favoriteColor: '',
hobbies: box([]),
dateOfBirth: new Date(Date.UTC(1970, 0, 1)).toISOString(),
agreeToTermsOfUse: false,
});
const validationFormGroupReducer = createFormStateReducerWithUpdate(updateGroup({
userName: validate(required),
password: (state, parentState) => {
if (!parentState.value.createAccount) {
return disable(state);
}
state = enable(state);
return updateGroup(state, {
password: validate(required, minLength(8)),
confirmPassword: validate(equalTo(state.value.password)),
});
},
agreeToTermsOfUse: validate(requiredTrue),
}));
const reducers = combineReducers({
}
export class SetSearchResultAction implements Action {
static readonly TYPE = 'asyncValidation/SET_SEARCH_RESULT';
readonly type = SetSearchResultAction.TYPE;
constructor(public results: string[]) { }
}
export const FORM_ID = 'asyncValidation';
export const INITIAL_STATE = createFormGroupState(FORM_ID, {
searchTerm: '',
numberOfResultsToShow: 5,
});
const formGroupReducerWithUpdate = createFormStateReducerWithUpdate(updateGroup({
searchTerm: validate(required),
numberOfResultsToShow: validate(required, greaterThan(0)),
}));
const reducers = combineReducers({
formState(s = INITIAL_STATE, a: Action) {
return formGroupReducerWithUpdate(s, a);
},
searchResults(s: string[] = [], a: Action) {
if (a.type === SetSearchResultAction.TYPE) {
return (a as SetSearchResultAction).results;
}
return s;
},
});