| Total Complexity | 3 |
| Complexity/F | 1.5 |
| Lines of Code | 41 |
| Function Count | 2 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | 'use strict'; |
||
| 2 | |||
| 3 | /** |
||
| 4 | * |
||
| 5 | * @module redux_validation |
||
| 6 | */ |
||
| 7 | |||
| 8 | var objectAssign = require( 'object-assign' ), |
||
| 9 | |||
| 10 | ValidationDispatcherCollection = { |
||
| 11 | dispatchers: [], |
||
| 12 | store: null, |
||
| 13 | formContentName: '', |
||
| 14 | onUpdate: function () { |
||
| 15 | var formContent = this.store.getState()[ this.formContentName ], |
||
| 16 | i; |
||
| 17 | for ( i = 0; i < this.dispatchers.length; i++ ) { |
||
| 18 | this.dispatchers[ i ].dispatchIfChanged( formContent, this.store ); |
||
| 19 | } |
||
| 20 | } |
||
| 21 | }, |
||
| 22 | |||
| 23 | /** |
||
| 24 | * |
||
| 25 | * @param {Object} store Redux store |
||
| 26 | * @param {ValidationDispatcher[]} dispatchers |
||
| 27 | * @param {string} formContentName Field name for the store to access form contents, e.g. 'donationFormContent' or 'membershipFormContent' |
||
| 28 | */ |
||
| 29 | createValidationDispatcherCollection = function ( store, dispatchers, formContentName ) { |
||
| 30 | var collection = objectAssign( Object.create( ValidationDispatcherCollection ), { |
||
| 31 | store: store, |
||
| 32 | dispatchers: dispatchers, |
||
| 33 | formContentName: formContentName |
||
| 34 | } ); |
||
| 35 | store.subscribe( collection.onUpdate.bind( collection ) ); |
||
| 36 | return collection; |
||
| 37 | }; |
||
| 38 | |||
| 39 | module.exports = { |
||
| 40 | createValidationDispatcherCollection: createValidationDispatcherCollection |
||
| 41 | }; |
||
| 42 |