Commit 9b5232a 1 parent 0f43122 commit 9b5232a Copy full SHA for 9b5232a
File tree 1 file changed +14
-2
lines changed
1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change 1
1
import has from 'lodash/has' ;
2
2
import isSchema from './util/isSchema' ;
3
3
4
+ function callOrConcat ( schema ) {
5
+ if ( typeof schema === 'function' )
6
+ return schema
7
+
8
+ return base => base . concat ( schema )
9
+ }
10
+
4
11
class Conditional {
5
12
6
13
constructor ( refs , options ) {
7
14
let { is, then, otherwise } = options ;
8
15
9
16
this . refs = [ ] . concat ( refs )
10
17
18
+ then = callOrConcat ( then ) ;
19
+ otherwise = callOrConcat ( otherwise ) ;
20
+
11
21
if ( typeof options === 'function' )
12
22
this . fn = options
13
23
else
@@ -24,8 +34,10 @@ class Conditional {
24
34
? is : ( ( ...values ) => values . every ( value => value === is ) )
25
35
26
36
this . fn = function ( ...values ) {
27
- let ctx = values . pop ( ) ;
28
- return isFn ( ...values ) ? ctx . concat ( then ) : ctx . concat ( otherwise )
37
+ let currentSchema = values . pop ( ) ;
38
+ let option = isFn ( ...values ) ? then : otherwise
39
+
40
+ return option ( currentSchema )
29
41
}
30
42
}
31
43
}
You can’t perform that action at this time.
0 commit comments