npm ngrx-forms 5.2.0

latest releases: 8.0.0, 7.0.0, 6.3.6...
5 years ago

Features

  • add function onNgrxFormsAction that allows specifying a reducer for ngrx-forms actions with createReducer from ngrx 8 (5cdf9c6)

    It can be used as follows:

    import { createReducer } from '@ngrx/store';
    import {
      onNgrxForms,
      onNgrxFormsAction,
      SetValueAction,
      updateGroup,
      validate,
      wrapReducerWithFormStateUpdate,
    } from 'ngrx-forms';
    import { required } from 'ngrx-forms/validation';
    
    export interface LoginFormValue {
      username: string;
      password: string;
      stayLoggedIn: boolean;
    }
    
    export const initialLoginFormValue: LoginFormValue = {
      username: '',
      password: '',
      stayLoggedIn: false,
    };
    
    export const validateLoginForm = updateGroup<LoginFormValue>({
      username: validate(required),
      password: validate(required),
    });
    
    const reducer = createReducer(
      {
        loginForm: createFormGroupState('loginForm', initialLoginFormValue),
        // your other properties...
      },
      onNgrxForms(),
    
      // use this to call a reducer for a specific ngrx-forms action;
      // note that this must be placed after onNgrxForms
      onNgrxFormsAction(SetValueAction, (state, action) => {
        if (action.controlId === 'loginForm.username') {
          // react to username changing...
          // action is of type SetValueAction
        }
    
        return state;
      }),
      // your other reducers...
    );

Don't miss a new ngrx-forms release

NewReleases is sending notifications on new releases.