@@ -2098,19 +2098,38 @@ var Cursor = function Cursor(rootData, keyPath, onChange, length) {
2098
2098
return m . remove ( key ) ;
2099
2099
} ) , key ) ;
2100
2100
} ,
2101
- update : function ( keyOrFn , notSetValue , updater ) {
2102
- return arguments . length === 1 ? updateCursor ( this , keyOrFn ) : updateCursor ( this , ( function ( map ) {
2103
- return map . update ( keyOrFn , notSetValue , updater ) ;
2104
- } ) , keyOrFn ) ;
2105
- } ,
2106
2101
updateIn : function ( keyPath , notSetValue , updater ) {
2107
2102
return updateCursor ( this , ( function ( m ) {
2108
2103
return m . updateIn ( keyPath , notSetValue , updater ) ;
2109
2104
} ) , keyPath ) ;
2110
2105
} ,
2106
+ merge : function ( ) {
2107
+ var args = arguments ;
2108
+ return updateCursor ( this , ( function ( m ) {
2109
+ return m . merge . apply ( m , args ) ;
2110
+ } ) ) ;
2111
+ } ,
2112
+ mergeWith : function ( ) {
2113
+ var args = arguments ;
2114
+ return updateCursor ( this , ( function ( m ) {
2115
+ return m . mergeWith . apply ( m , args ) ;
2116
+ } ) ) ;
2117
+ } ,
2118
+ mergeDeep : function ( ) {
2119
+ var args = arguments ;
2120
+ return updateCursor ( this , ( function ( m ) {
2121
+ return m . mergeDeep . apply ( m , args ) ;
2122
+ } ) ) ;
2123
+ } ,
2124
+ mergeDeepWith : function ( ) {
2125
+ var args = arguments ;
2126
+ return updateCursor ( this , ( function ( m ) {
2127
+ return m . mergeDeepWith . apply ( m , args ) ;
2128
+ } ) ) ;
2129
+ } ,
2111
2130
clear : function ( ) {
2112
2131
return updateCursor ( this , ( function ( m ) {
2113
- return m . clear ( ) ;
2132
+ return m && m . clear ( ) ;
2114
2133
} ) ) ;
2115
2134
} ,
2116
2135
cursor : function ( maybeKeyPath , onChange ) {
@@ -2125,17 +2144,17 @@ var Cursor = function Cursor(rootData, keyPath, onChange, length) {
2125
2144
} ,
2126
2145
withMutations : function ( fn ) {
2127
2146
return updateCursor ( this , ( function ( m ) {
2128
- return ( m || Map . empty ( ) ) . withMutations ( fn ) ;
2147
+ return m . withMutations ( fn ) ;
2129
2148
} ) ) ;
2130
2149
} ,
2131
2150
asMutable : function ( ) {
2132
2151
return updateCursor ( this , ( function ( m ) {
2133
- return ( m || Map . empty ( ) ) . asMutable ( ) ;
2152
+ return m . asMutable ( ) ;
2134
2153
} ) ) ;
2135
2154
} ,
2136
2155
asImmutable : function ( ) {
2137
2156
return updateCursor ( this , ( function ( m ) {
2138
- return ( m || Map . empty ( ) ) . asImmutable ( ) ;
2157
+ return m . asImmutable ( ) ;
2139
2158
} ) ) ;
2140
2159
} ,
2141
2160
__iterate : function ( fn , reverse ) {
@@ -2165,6 +2184,7 @@ var Cursor = function Cursor(rootData, keyPath, onChange, length) {
2165
2184
}
2166
2185
} , { } , Sequence ) ;
2167
2186
Cursor . prototype [ DELETE ] = Cursor . prototype . remove ;
2187
+ Cursor . prototype . update = MapPrototype . update ;
2168
2188
function makeCursor ( rootData , keyPath , onChange , value ) {
2169
2189
if ( arguments . length < 4 ) {
2170
2190
value = rootData . getIn ( keyPath ) ;
@@ -2179,20 +2199,23 @@ function subCursor(cursor, key, value) {
2179
2199
return makeCursor ( cursor . _rootData , cursor . _keyPath . concat ( key ) , cursor . _onChange , value ) ;
2180
2200
}
2181
2201
function updateCursor ( cursor , changeFn , changeKey ) {
2182
- var updatingSelf = arguments . length < 3 || ( Array . isArray ( changeKey ) && changeKey . length === 0 ) ;
2183
2202
var rootData = cursor . _rootData ;
2184
- var editPath = cursor . _keyPath || [ ] ;
2185
- if ( ! updatingSelf ) {
2203
+ var keyPath = cursor . _keyPath ;
2204
+ var onChange = cursor . _onChange ;
2205
+ var editPath = keyPath || [ ] ;
2206
+ if ( arguments . length > 2 ) {
2186
2207
editPath = editPath . concat ( changeKey ) ;
2187
2208
}
2188
- var updateIn = applyUpdateIn ( cursor . _keyPath , updatingSelf ? undefined : Map . empty ( ) , changeFn ) ;
2209
+ var updateIn = applyUpdateIn ( keyPath , changeFn ) ;
2189
2210
var newRootData = typeof rootData . deref === 'function' ? updateCursor ( rootData , updateIn , editPath ) : updateIn ( rootData ) ;
2190
- cursor . _onChange && cursor . _onChange ( newRootData , rootData , editPath ) ;
2191
- return makeCursor ( newRootData , cursor . _keyPath , cursor . _onChange ) ;
2211
+ onChange && onChange ( newRootData , rootData , editPath ) ;
2212
+ return makeCursor ( newRootData , keyPath , onChange ) ;
2192
2213
}
2193
- function applyUpdateIn ( keyPath , notSetValue , changeFn ) {
2214
+ function applyUpdateIn ( keyPath , changeFn ) {
2194
2215
return function ( collection ) {
2195
- return collection . updateIn ( keyPath , notSetValue , changeFn ) ;
2216
+ return collection . updateIn ( keyPath , ( function ( prev ) {
2217
+ return changeFn ( prev instanceof Map ? prev : Map . empty ( ) ) ;
2218
+ } ) ) ;
2196
2219
} ;
2197
2220
}
2198
2221
var Vector = function Vector ( ) {
0 commit comments