File tree Expand file tree Collapse file tree 2 files changed +10
-16
lines changed
packages/node_modules/proxy-state-tree/src Expand file tree Collapse file tree 2 files changed +10
-16
lines changed Original file line number Diff line number Diff line change @@ -47,6 +47,8 @@ export class Proxifier {
4747 } "`
4848 )
4949 }
50+
51+ return value
5052 }
5153
5254 trackPath ( path : string ) {
@@ -102,7 +104,9 @@ export class Proxifier {
102104 if ( prop === IS_PROXY ) return true
103105 if ( prop === PATH ) return path
104106 if ( prop === VALUE ) return value
105-
107+ if ( prop === 'indexOf' ) {
108+ return ( arg ) => value . indexOf ( arg && arg [ IS_PROXY ] ? arg [ VALUE ] : arg )
109+ }
106110 if (
107111 prop === 'length' ||
108112 ( typeof target [ prop ] === 'function' &&
@@ -112,10 +116,6 @@ export class Proxifier {
112116 return target [ prop ]
113117 }
114118
115- if ( prop === 'indexOf' ) {
116- return ( arg ) => value . indexOf ( arg && arg [ IS_PROXY ] ? arg [ VALUE ] : arg )
117- }
118-
119119 const trackingTree = proxifier . getTrackingTree ( )
120120 const nestedPath = proxifier . concat ( path , prop )
121121 const currentTree = trackingTree || proxifier . tree
@@ -137,7 +137,11 @@ export class Proxifier {
137137 hasChangedValue : true ,
138138 } )
139139
140- return target [ prop ] ( ...args )
140+ return target [ prop ] (
141+ ...args . map ( ( arg ) =>
142+ proxifier . ensureValueDosntExistInStateTreeElsewhere ( arg )
143+ )
144+ )
141145 }
142146 }
143147
Original file line number Diff line number Diff line change @@ -367,16 +367,6 @@ describe('ARRAYS', () => {
367367 mutationTree . flush ( )
368368 expect ( currentProxy ) . not . toBe ( newProxy )
369369 } )
370-
371- test ( 'should track with indexOf' , ( ) => {
372- const state = {
373- foo : [ 'bar' ] ,
374- }
375- const tree = new ProxyStateTree ( state )
376- const accessTree = tree . getTrackStateTree ( ) . track ( ( ) => { } )
377- expect ( accessTree . state . foo . indexOf ( 'bar' ) ) . toBe ( 0 )
378- expect ( accessTree . pathDependencies ) . toEqual ( new Set ( [ 'foo' , 'foo.0' ] ) )
379- } )
380370 } )
381371
382372 describe ( 'MUTATIONS' , ( ) => {
You can’t perform that action at this time.
0 commit comments