@@ -4,83 +4,84 @@ import mapValues from '../utils/map-values';
4
4
import actionTypes from '../action-types' ;
5
5
import batchActions from './batch-actions' ;
6
6
import { getValidity , getForm , isValid , isInvalid } from '../utils' ;
7
+ import { trackable } from '../utils/track' ;
7
8
8
- const focus = model => ( {
9
+ const focus = trackable ( ( model ) => ( {
9
10
type : actionTypes . FOCUS ,
10
11
model,
11
- } ) ;
12
+ } ) ) ;
12
13
13
- const blur = model => ( {
14
+ const blur = trackable ( ( model ) => ( {
14
15
type : actionTypes . BLUR ,
15
16
model,
16
- } ) ;
17
+ } ) ) ;
17
18
18
- const setPristine = model => ( {
19
+ const setPristine = trackable ( ( model ) => ( {
19
20
type : actionTypes . SET_PRISTINE ,
20
21
model,
21
- } ) ;
22
+ } ) ) ;
22
23
23
- const setDirty = model => ( {
24
+ const setDirty = trackable ( ( model ) => ( {
24
25
type : actionTypes . SET_DIRTY ,
25
26
model,
26
- } ) ;
27
+ } ) ) ;
27
28
28
- const setInitial = model => ( {
29
+ const setInitial = trackable ( ( model ) => ( {
29
30
type : actionTypes . SET_INITIAL ,
30
31
model,
31
- } ) ;
32
+ } ) ) ;
32
33
33
- const setPending = ( model , pending = true ) => ( {
34
+ const setPending = trackable ( ( model , pending = true ) => ( {
34
35
type : actionTypes . SET_PENDING ,
35
36
model,
36
37
pending,
37
- } ) ;
38
+ } ) ) ;
38
39
39
- const setValidity = ( model , validity , options = { } ) => ( {
40
+ const setValidity = trackable ( ( model , validity , options = { } ) => ( {
40
41
type : options . errors
41
42
? actionTypes . SET_ERRORS
42
43
: actionTypes . SET_VALIDITY ,
43
44
model,
44
45
[ options . errors ? 'errors' : 'validity' ] : validity ,
45
- } ) ;
46
+ } ) ) ;
46
47
47
- const setFieldsValidity = ( model , fieldsValidity , options = { } ) => ( {
48
+ const setFieldsValidity = trackable ( ( model , fieldsValidity , options = { } ) => ( {
48
49
type : actionTypes . SET_FIELDS_VALIDITY ,
49
50
model,
50
51
fieldsValidity,
51
52
options,
52
- } ) ;
53
+ } ) ) ;
53
54
54
- const setErrors = ( model , errors , options = { } ) =>
55
+ const setErrors = trackable ( ( model , errors , options = { } ) =>
55
56
setValidity ( model , errors , {
56
57
...options ,
57
58
errors : true ,
58
- } ) ;
59
+ } ) ) ;
59
60
60
- const setFieldsErrors = ( model , fieldsErrors , options ) =>
61
+ const setFieldsErrors = trackable ( ( model , fieldsErrors , options ) =>
61
62
setFieldsValidity ( model , fieldsErrors , {
62
63
...options ,
63
64
errors : true ,
64
- } ) ;
65
+ } ) ) ;
65
66
66
- const resetValidity = ( model ) => ( {
67
+ const resetValidity = trackable ( ( model ) => ( {
67
68
type : actionTypes . RESET_VALIDITY ,
68
69
model,
69
- } ) ;
70
+ } ) ) ;
70
71
71
72
const resetErrors = resetValidity ;
72
73
73
- const setTouched = model => ( {
74
+ const setTouched = trackable ( ( model ) => ( {
74
75
type : actionTypes . SET_TOUCHED ,
75
76
model,
76
- } ) ;
77
+ } ) ) ;
77
78
78
- const setUntouched = model => ( {
79
+ const setUntouched = trackable ( ( model ) => ( {
79
80
type : actionTypes . SET_UNTOUCHED ,
80
81
model,
81
- } ) ;
82
+ } ) ) ;
82
83
83
- const asyncSetValidity = ( model , validator ) => ( dispatch , getState ) => {
84
+ const asyncSetValidity = trackable ( ( model , validator ) => ( dispatch , getState ) => {
84
85
const value = _get ( getState ( ) , model ) ;
85
86
86
87
dispatch ( setPending ( model , true ) ) ;
@@ -97,27 +98,27 @@ const asyncSetValidity = (model, validator) => (dispatch, getState) => {
97
98
if ( typeof immediateResult !== 'undefined' ) {
98
99
done ( immediateResult ) ;
99
100
}
100
- } ;
101
+ } ) ;
101
102
102
- const setSubmitted = ( model , submitted = true ) => ( {
103
+ const setSubmitted = trackable ( ( model , submitted = true ) => ( {
103
104
type : actionTypes . SET_SUBMITTED ,
104
105
model,
105
106
submitted,
106
- } ) ;
107
+ } ) ) ;
107
108
108
- const setSubmitFailed = ( model ) => ( {
109
+ const setSubmitFailed = trackable ( ( model ) => ( {
109
110
type : actionTypes . SET_SUBMIT_FAILED ,
110
111
model,
111
- } ) ;
112
+ } ) ) ;
112
113
113
114
114
- const setViewValue = ( model , value ) => ( {
115
+ const setViewValue = trackable ( ( model , value ) => ( {
115
116
type : actionTypes . SET_VIEW_VALUE ,
116
117
model,
117
118
value,
118
- } ) ;
119
+ } ) ) ;
119
120
120
- const submit = ( model , promise , options = { } ) => dispatch => {
121
+ const submit = trackable ( ( model , promise , options = { } ) => dispatch => {
121
122
dispatch ( setPending ( model , true ) ) ;
122
123
123
124
const errorsAction = options . fields
@@ -137,29 +138,29 @@ const submit = (model, promise, options = {}) => dispatch => {
137
138
} ) ;
138
139
139
140
return promise ;
140
- } ;
141
+ } ) ;
141
142
142
- const submitFields = ( model , promise , options = { } ) =>
143
+ const submitFields = trackable ( ( model , promise , options = { } ) =>
143
144
submit ( model , promise , {
144
145
...options ,
145
146
fields : true ,
146
- } ) ;
147
+ } ) ) ;
147
148
148
- const validate = ( model , validators ) => ( dispatch , getState ) => {
149
+ const validate = trackable ( ( model , validators ) => ( dispatch , getState ) => {
149
150
const value = _get ( getState ( ) , model ) ;
150
151
const validity = getValidity ( validators , value ) ;
151
152
152
153
dispatch ( setValidity ( model , validity ) ) ;
153
- } ;
154
+ } ) ;
154
155
155
- const validateErrors = ( model , errorValidators ) => ( dispatch , getState ) => {
156
+ const validateErrors = trackable ( ( model , errorValidators ) => ( dispatch , getState ) => {
156
157
const value = _get ( getState ( ) , model ) ;
157
158
const errors = getValidity ( errorValidators , value ) ;
158
159
159
160
dispatch ( setValidity ( model , errors , { errors : true } ) ) ;
160
- } ;
161
+ } ) ;
161
162
162
- const validateFields = ( model , fieldValidators , options = { } ) => ( dispatch , getState ) => {
163
+ const validateFields = trackable ( ( model , fieldValidators , options = { } ) => ( dispatch , getState ) => {
163
164
const value = _get ( getState ( ) , model ) ;
164
165
165
166
const fieldsValidity = mapValues ( fieldValidators , ( validator , field ) => {
@@ -196,13 +197,13 @@ const validateFields = (model, fieldValidators, options = {}) => (dispatch, getS
196
197
: setFieldsValidity ;
197
198
198
199
dispatch ( fieldsValiditySetter ( model , fieldsValidity ) ) ;
199
- } ;
200
+ } ) ;
200
201
201
- const validateFieldsErrors = ( model , fieldErrorsValidators , options = { } ) =>
202
+ const validateFieldsErrors = trackable ( ( model , fieldErrorsValidators , options = { } ) =>
202
203
validateFields ( model , fieldErrorsValidators , {
203
204
...options ,
204
205
errors : true ,
205
- } ) ;
206
+ } ) ) ;
206
207
207
208
export default {
208
209
asyncSetValidity,
0 commit comments