|
5 | 5 |
|
6 | 6 | #### Features |
7 | 7 |
|
| 8 | +* add functions `onNgrxForms` and `wrapReducerWithFormStateUpdate` to allow better integration with `createReducer` from ngrx 8 ([ac95be2](https://github.com/MrWolfZ/ngrx-forms/commit/ac95be2)), closes [#147](https://github.com/MrWolfZ/ngrx-forms/issues/147) |
| 9 | + |
| 10 | + They can be used as follows: |
| 11 | + |
| 12 | + ```ts |
| 13 | + import { createReducer } from '@ngrx/store'; |
| 14 | + import { onNgrxForms, updateGroup, validate, wrapReducerWithFormStateUpdate } from 'ngrx-forms'; |
| 15 | + import { required } from 'ngrx-forms/validation'; |
| 16 | + |
| 17 | + export interface LoginFormValue { |
| 18 | + username: string; |
| 19 | + password: string; |
| 20 | + stayLoggedIn: boolean; |
| 21 | + } |
| 22 | + |
| 23 | + export const initialLoginFormValue: LoginFormValue = { |
| 24 | + username: '', |
| 25 | + password: '', |
| 26 | + stayLoggedIn: false, |
| 27 | + }; |
| 28 | + |
| 29 | + export const validateLoginForm = updateGroup<LoginFormValue>({ |
| 30 | + username: validate(required), |
| 31 | + password: validate(required), |
| 32 | + }); |
| 33 | + |
| 34 | + const rawReducer = createReducer( |
| 35 | + { |
| 36 | + loginForm: createFormGroupState('loginForm', initialLoginFormValue), |
| 37 | + // your other properties... |
| 38 | + }, |
| 39 | + onNgrxForms(), |
| 40 | + // your other reducers... |
| 41 | + ); |
| 42 | + |
| 43 | + // wrapReducerWithFormStateUpdate calls the update function |
| 44 | + // after the given reducer; you can wrap this reducer again |
| 45 | + // if you have multiple forms in your state |
| 46 | + export const reducer = wrapReducerWithFormStateUpdate( |
| 47 | + rawReducer, |
| 48 | + // point to the form state to update |
| 49 | + s => s.loginForm, |
| 50 | + // this function is always called after the reducer |
| 51 | + validateLoginForm, |
| 52 | + ); |
| 53 | + ``` |
8 | 54 | * add update functions for async validations ([8985e99](https://github.com/MrWolfZ/ngrx-forms/commit/8985e99)) |
9 | 55 | * export constant `ALL_NGRX_FORMS_ACTION_TYPES` that is an array of all action types ngrx-forms provides ([09aad36](https://github.com/MrWolfZ/ngrx-forms/commit/09aad36)) |
10 | 56 |
|
|
0 commit comments