6
6
*/
7
7
8
8
import { is } from './is' ;
9
- import { setIn } from './functional/setIn' ;
10
- import { update } from './functional/update' ;
11
- import { updateIn } from './functional/updateIn' ;
12
- import { removeIn } from './functional/removeIn' ;
13
- import { merge , mergeDeep , mergeDeepWith } from './functional/merge' ;
14
9
import { Collection , KeyedCollection } from './Collection' ;
15
10
import { isOrdered } from './Predicates' ;
16
11
import {
@@ -30,6 +25,18 @@ import { Iterator, iteratorValue, iteratorDone } from './Iterator';
30
25
import { sortFactory } from './Operations' ;
31
26
import arrCopy from './utils/arrCopy' ;
32
27
import assertNotInfinite from './utils/assertNotInfinite' ;
28
+ import { setIn } from './methods/setIn' ;
29
+ import { deleteIn } from './methods/deleteIn' ;
30
+ import { update } from './methods/update' ;
31
+ import { updateIn } from './methods/updateIn' ;
32
+ import { merge , mergeWith } from './methods/merge' ;
33
+ import { mergeDeep , mergeDeepWith } from './methods/mergeDeep' ;
34
+ import { mergeIn } from './methods/mergeIn' ;
35
+ import { mergeDeepIn } from './methods/mergeDeepIn' ;
36
+ import { withMutations } from './methods/withMutations' ;
37
+ import { asMutable } from './methods/asMutable' ;
38
+ import { asImmutable } from './methods/asImmutable' ;
39
+ import { wasAltered } from './methods/wasAltered' ;
33
40
34
41
import { OrderedMap } from './OrderedMap' ;
35
42
@@ -77,18 +84,10 @@ export class Map extends KeyedCollection {
77
84
return updateMap ( this , k , v ) ;
78
85
}
79
86
80
- setIn ( keyPath , v ) {
81
- return setIn ( this , keyPath , v ) ;
82
- }
83
-
84
87
remove ( k ) {
85
88
return updateMap ( this , k , NOT_SET ) ;
86
89
}
87
90
88
- deleteIn ( keyPath ) {
89
- return removeIn ( this , keyPath ) ;
90
- }
91
-
92
91
deleteAll ( keys ) {
93
92
const collection = Collection ( keys ) ;
94
93
@@ -101,16 +100,6 @@ export class Map extends KeyedCollection {
101
100
} ) ;
102
101
}
103
102
104
- update ( key , notSetValue , updater ) {
105
- return arguments . length === 1
106
- ? key ( this )
107
- : update ( this , key , notSetValue , updater ) ;
108
- }
109
-
110
- updateIn ( keyPath , notSetValue , updater ) {
111
- return updateIn ( this , keyPath , notSetValue , updater ) ;
112
- }
113
-
114
103
clear ( ) {
115
104
if ( this . size === 0 ) {
116
105
return this ;
@@ -127,30 +116,6 @@ export class Map extends KeyedCollection {
127
116
128
117
// @pragma Composition
129
118
130
- merge ( /*...iters*/ ) {
131
- return mergeIntoMapWith ( this , undefined , arguments ) ;
132
- }
133
-
134
- mergeWith ( merger , ...iters ) {
135
- return mergeIntoMapWith ( this , merger , iters ) ;
136
- }
137
-
138
- mergeIn ( keyPath , ...iters ) {
139
- return updateIn ( this , keyPath , emptyMap ( ) , m => merge ( m , ...iters ) ) ;
140
- }
141
-
142
- mergeDeep ( ...iters ) {
143
- return mergeDeep ( this , ...iters ) ;
144
- }
145
-
146
- mergeDeepWith ( merger , ...iters ) {
147
- return mergeDeepWith ( merger , this , ...iters ) ;
148
- }
149
-
150
- mergeDeepIn ( keyPath , ...iters ) {
151
- return updateIn ( this , keyPath , emptyMap ( ) , m => mergeDeep ( m , ...iters ) ) ;
152
- }
153
-
154
119
sort ( comparator ) {
155
120
// Late binding
156
121
return OrderedMap ( sortFactory ( this , comparator ) ) ;
@@ -163,24 +128,6 @@ export class Map extends KeyedCollection {
163
128
164
129
// @pragma Mutability
165
130
166
- withMutations ( fn ) {
167
- const mutable = this . asMutable ( ) ;
168
- fn ( mutable ) ;
169
- return mutable . wasAltered ( ) ? mutable . __ensureOwner ( this . __ownerID ) : this ;
170
- }
171
-
172
- asMutable ( ) {
173
- return this . __ownerID ? this : this . __ensureOwner ( new OwnerID ( ) ) ;
174
- }
175
-
176
- asImmutable ( ) {
177
- return this . __ensureOwner ( ) ;
178
- }
179
-
180
- wasAltered ( ) {
181
- return this . __altered ;
182
- }
183
-
184
131
__iterator ( type , reverse ) {
185
132
return new MapIterator ( this , type , reverse ) ;
186
133
}
@@ -222,10 +169,22 @@ const IS_MAP_SENTINEL = '@@__IMMUTABLE_MAP__@@';
222
169
export const MapPrototype = Map . prototype ;
223
170
MapPrototype [ IS_MAP_SENTINEL ] = true ;
224
171
MapPrototype [ DELETE ] = MapPrototype . remove ;
225
- MapPrototype . removeIn = MapPrototype . deleteIn ;
226
172
MapPrototype . removeAll = MapPrototype . deleteAll ;
227
173
MapPrototype . concat = MapPrototype . merge ;
228
- MapPrototype [ '@@transducer/init' ] = MapPrototype . asMutable ;
174
+ MapPrototype . setIn = setIn ;
175
+ MapPrototype . removeIn = MapPrototype . deleteIn = deleteIn ;
176
+ MapPrototype . update = update ;
177
+ MapPrototype . updateIn = updateIn ;
178
+ MapPrototype . merge = merge ;
179
+ MapPrototype . mergeWith = mergeWith ;
180
+ MapPrototype . mergeDeep = mergeDeep ;
181
+ MapPrototype . mergeDeepWith = mergeDeepWith ;
182
+ MapPrototype . mergeIn = mergeIn ;
183
+ MapPrototype . mergeDeepIn = mergeDeepIn ;
184
+ MapPrototype . withMutations = withMutations ;
185
+ MapPrototype . wasAltered = wasAltered ;
186
+ MapPrototype . asImmutable = asImmutable ;
187
+ MapPrototype [ '@@transducer/init' ] = MapPrototype . asMutable = asMutable ;
229
188
MapPrototype [ '@@transducer/step' ] = function ( result , arr ) {
230
189
return result . set ( arr [ 0 ] , arr [ 1 ] ) ;
231
190
} ;
@@ -806,39 +765,6 @@ function expandNodes(ownerID, nodes, bitmap, including, node) {
806
765
return new HashArrayMapNode ( ownerID , count + 1 , expandedNodes ) ;
807
766
}
808
767
809
- function mergeIntoMapWith ( collection , merger , collections ) {
810
- const iters = [ ] ;
811
- for ( let ii = 0 ; ii < collections . length ; ii ++ ) {
812
- const collection = KeyedCollection ( collections [ ii ] ) ;
813
- if ( collection . size !== 0 ) {
814
- iters . push ( collection ) ;
815
- }
816
- }
817
- if ( iters . length === 0 ) {
818
- return collection ;
819
- }
820
- if ( collection . size === 0 && ! collection . __ownerID && iters . length === 1 ) {
821
- return collection . constructor ( iters [ 0 ] ) ;
822
- }
823
- return collection . withMutations ( collection => {
824
- const mergeIntoCollection = merger
825
- ? ( value , key ) => {
826
- update (
827
- collection ,
828
- key ,
829
- NOT_SET ,
830
- oldVal => ( oldVal === NOT_SET ? value : merger ( oldVal , value , key ) )
831
- ) ;
832
- }
833
- : ( value , key ) => {
834
- collection . set ( key , value ) ;
835
- } ;
836
- for ( let ii = 0 ; ii < iters . length ; ii ++ ) {
837
- iters [ ii ] . forEach ( mergeIntoCollection ) ;
838
- }
839
- } ) ;
840
- }
841
-
842
768
function popCount ( x ) {
843
769
x -= ( x >> 1 ) & 0x55555555 ;
844
770
x = ( x & 0x33333333 ) + ( ( x >> 2 ) & 0x33333333 ) ;
0 commit comments