File tree Expand file tree Collapse file tree 3 files changed +20
-20
lines changed
Expand file tree Collapse file tree 3 files changed +20
-20
lines changed Original file line number Diff line number Diff line change @@ -136,6 +136,7 @@ describe('Derived', () => {
136136 app . actions . addDerived ( )
137137 expect ( app . state . upperFoo ) . toBe ( 'BAR' )
138138 app . actions . changeFoo ( )
139+
139140 expect ( app . state . upperFoo ) . toBe ( 'BAR2' )
140141 } )
141142
Original file line number Diff line number Diff line change @@ -13,7 +13,6 @@ export const IS_DERIVED = Symbol('IS_DERIVED')
1313
1414export class Derived {
1515 private isDirty : boolean = true
16- private trackStateTree : ITrackStateTree < any >
1716 private previousProxifier : any
1817 private value : any
1918 private paths : Set < string >
@@ -46,7 +45,6 @@ export class Derived {
4645 if ( ! this . disposeOnMutation ) {
4746 this . disposeOnMutation = proxyStateTree . onMutation (
4847 ( _ , paths , flushId ) => {
49- // It has been removed from the tree
5048 if ( typeof path . reduce ( ( aggr , key ) => aggr && aggr [ key ] , proxyStateTree . sourceState ) !== 'function' ) {
5149 this . disposeOnMutation ( )
5250 return
Original file line number Diff line number Diff line change @@ -341,32 +341,33 @@ export class Proxifier {
341341 const mutationTree = proxifier . getMutationTree ( )
342342 const existingValue = target [ prop ]
343343
344+ // Adding functions is not considered mutations
344345 if ( typeof value === 'function' && proxifier . tree . master . options . onFunction ) {
345346 const result = proxifier . tree . master . options . onFunction (
346- proxifier . tree ,
347+ proxifier . getTrackingTree ( ) || proxifier . tree ,
347348 nestedPath ,
348349 value
349350 )
350351
351352 value = result . func
352- }
353-
354- mutationTree . addMutation (
355- {
356- method : 'set' ,
357- path : nestedPath ,
358- args : [ value ] ,
359- hasChangedValue : value !== target [ prop ] ,
360- revert : ( ) => {
361- if ( existingValue === undefined ) {
362- delete proxy [ prop ]
363- } else {
364- proxy [ prop ] = existingValue
365- }
353+ } else {
354+ mutationTree . addMutation (
355+ {
356+ method : 'set' ,
357+ path : nestedPath ,
358+ args : [ value ] ,
359+ hasChangedValue : value !== target [ prop ] ,
360+ revert : ( ) => {
361+ if ( existingValue === undefined ) {
362+ delete proxy [ prop ]
363+ } else {
364+ proxy [ prop ] = existingValue
365+ }
366+ } ,
366367 } ,
367- } ,
368- objectChangePath
369- )
368+ objectChangePath
369+ )
370+ }
370371
371372 return Reflect . set ( target , prop , value )
372373 } ,
You can’t perform that action at this time.
0 commit comments