File tree Expand file tree Collapse file tree 2 files changed +29
-6
lines changed Expand file tree Collapse file tree 2 files changed +29
-6
lines changed Original file line number Diff line number Diff line change @@ -87,6 +87,20 @@ describe('updateIn', () => {
87
87
} ) ;
88
88
} ) ;
89
89
90
+ it ( 'deep set with numeric key 1' , ( ) => {
91
+ const m = fromJS ( { a : { b : 1 } } ) ;
92
+ expect ( m . updateIn ( [ 'a' , 'c' , 0 ] , ( ) => 20 ) . toJS ( ) ) . toEqual ( {
93
+ a : { b : 1 , c : [ 20 ] } ,
94
+ } ) ;
95
+ } ) ;
96
+
97
+ it ( 'deep set with numeric key 2' , ( ) => {
98
+ const m = fromJS ( { } ) ;
99
+ expect ( m . updateIn ( [ 'a' , 0 ] , ( ) => 20 ) . toJS ( ) ) . toEqual ( {
100
+ a : [ 20 ] ,
101
+ } ) ;
102
+ } ) ;
103
+
90
104
it ( 'deep push' , ( ) => {
91
105
const m = fromJS ( { a : { b : [ 1 , 2 , 3 ] } } ) ;
92
106
expect ( m . updateIn ( [ 'a' , 'b' ] , list => list . push ( 4 ) ) . toJS ( ) ) . toEqual ( {
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import isDataStructure from '../utils/isDataStructure';
11
11
import quoteString from '../utils/quoteString' ;
12
12
import { NOT_SET } from '../TrieUtils' ;
13
13
import { emptyMap } from '../Map' ;
14
+ import { emptyList } from '../List' ;
14
15
import { get } from './get' ;
15
16
import { remove } from './remove' ;
16
17
import { set } from './set' ;
@@ -66,10 +67,18 @@ function updateInDeeply(
66
67
return nextUpdated === nextExisting
67
68
? existing
68
69
: nextUpdated === NOT_SET
69
- ? remove ( existing , key )
70
- : set (
71
- wasNotSet ? ( inImmutable ? emptyMap ( ) : { } ) : existing ,
72
- key ,
73
- nextUpdated
74
- ) ;
70
+ ? remove ( existing , key )
71
+ : set (
72
+ wasNotSet
73
+ ? inImmutable
74
+ ? typeof key === 'number'
75
+ ? emptyList ( )
76
+ : emptyMap ( )
77
+ : typeof key === 'number'
78
+ ? [ ]
79
+ : { }
80
+ : existing ,
81
+ key ,
82
+ nextUpdated
83
+ ) ;
75
84
}
You can’t perform that action at this time.
0 commit comments