Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should properly infer value type when used with validate update function', () => {
// this code is never meant to be executed, it should just pass the type checker
if (1 !== 1) {
const state: AbstractControlState = undefined!;
const v = validate(state, greaterThanOrEqualTo(0));
const v2: number = v.value;
console.log(v2);
}
});
});
it('should properly infer value type when used with validate update function', () => {
// this code is never meant to be executed, it should just pass the type checker
if (1 !== 1) {
const state: AbstractControlState = undefined!;
const v = validate(state, minLength(2));
const v2: string = v.value;
console.log(v2);
}
});
});
it('should properly infer value type when used with validate update function', () => {
// this code is never meant to be executed, it should just pass the type checker
if (1 !== 1) {
const state: AbstractControlState = undefined!;
const v = validate(state, required);
const v2: number = v.value;
console.log(v2);
}
});
});
it('should properly infer value type when used with validate update function', () => {
// this code is never meant to be executed, it should just pass the type checker
if (1 !== 1) {
const state: AbstractControlState = undefined!;
const v = validate(state, lessThan(2));
const v2: number = v.value;
console.log(v2);
}
});
});
it('should properly infer value type when used with validate update function', () => {
// this code is never meant to be executed, it should just pass the type checker
if (1 !== 1) {
const state: AbstractControlState = undefined!;
const v = validate(state, greaterThan(0));
const v2: number = v.value;
console.log(v2);
}
});
});
it('should properly infer value type when used with validate update function', () => {
// this code is never meant to be executed, it should just pass the type checker
if (1 !== 1) {
const state: AbstractControlState = undefined!;
const v = validate(state, requiredTrue);
const v2: boolean = v.value;
console.log(v2);
}
});
});
});
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({
formState(s = INITIAL_STATE, a: Action) {
return validationFormGroupReducer(s, a);
},
submittedValue(s: FormValue | undefined, a: SetSubmittedValueAction) {
switch (a.type) {
case SetSubmittedValueAction.TYPE:
return a.submittedValue;
default:
return s;
}
},
});
import { Action } from '@ngrx/store';
import { groupUpdateReducer, updateGroup, setValue, validate, enable, disable, cast, compose } from 'ngrx-forms';
import { AppState, initialState, ITEM_FORM_ID } from './app.state';
import { Actions, AddTodoItemAction } from './app.actions';
import { ItemFormValue, MetaFormValue, validateText, validatePriority, validateDuedate } from './item-form/item-form.state';
const itemFormReducer = groupUpdateReducer({
text: validate(validateText),
meta: updateGroup({
priority: validate(validatePriority),
duedate: validate(validateDuedate),
}),
}, {
meta: (meta, itemForm) => updateGroup({
priority: priority => {
if (itemForm.value.category === 'Private') {
return setValue(0, disable(priority));
}
return priority.isEnabled ? priority : setValue(1, enable(priority));
},
})(cast(meta)),
});
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;
},
});
export function reducer(s: State['asyncValidation'], a: Action) {
import { Action } from '@ngrx/store';
import { groupUpdateReducer, updateGroup, setValue, validate, enable, disable, cast, compose } from 'ngrx-forms';
import { AppState, initialState, ITEM_FORM_ID } from './app.state';
import { Actions, AddTodoItemAction } from './app.actions';
import { ItemFormValue, MetaFormValue, validateText, validatePriority, validateDuedate } from './item-form/item-form.state';
const itemFormReducer = groupUpdateReducer({
text: validate(validateText),
meta: updateGroup({
priority: validate(validatePriority),
duedate: validate(validateDuedate),
}),
}, {
meta: (meta, itemForm) => updateGroup({
priority: priority => {
if (itemForm.value.category === 'Private') {
return setValue(0, disable(priority));
}
return priority.isEnabled ? priority : setValue(1, enable(priority));
},
})(cast(meta)),
});
export function appReducer(state = initialState, action: Actions): AppState {
const itemForm = itemFormReducer(state.itemForm, action);
if (itemForm !== state.itemForm) {