File tree Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -334,8 +334,8 @@ export function evaluate(reactorState, keyPathOrGetter) {
334334
335335 const cache = reactorState . get ( 'cache' )
336336 var cacheEntry = cache . lookup ( keyPathOrGetter )
337- const isCacheMiss = ! cacheEntry
338- if ( isCacheMiss || isDirtyCacheEntry ( reactorState , cacheEntry ) ) {
337+ const isCacheMiss = ! cacheEntry || isDirtyCacheEntry ( reactorState , cacheEntry )
338+ if ( isCacheMiss ) {
339339 cacheEntry = createCacheEntry ( reactorState , keyPathOrGetter )
340340 }
341341
Original file line number Diff line number Diff line change @@ -595,6 +595,24 @@ describe('Reactor', () => {
595595 expect ( taxPercentSpy . calls . count ( ) ) . toEqual ( 2 )
596596 expect ( subtotalSpy . calls . count ( ) ) . toEqual ( 1 )
597597 } )
598+
599+ it ( 'should update cache with updated item after action' , ( ) => {
600+ const lastItemGetter = [ [ 'items' , 'all' ] , ( items ) => items . last ( ) ]
601+
602+ // ensure its in cache
603+ const lastItemBefore = reactor . evaluate ( lastItemGetter )
604+ const cacheEntryBefore = reactor . reactorState . cache . lookup ( lastItemGetter )
605+ expect ( lastItemBefore === cacheEntryBefore . value ) . toBe ( true )
606+
607+ checkoutActions . addItem ( 'potato' , 0.80 )
608+
609+ const lastItemAfter = reactor . evaluate ( lastItemGetter )
610+ const cacheEntryAfter = reactor . reactorState . cache . lookup ( lastItemGetter )
611+ expect ( lastItemAfter === cacheEntryAfter . value ) . toBe ( true )
612+
613+ // sanity check that lastItem actually changed for completeness
614+ expect ( lastItemAfter !== lastItemBefore ) . toBe ( true )
615+ } )
598616 } )
599617
600618 describe ( '#observe' , ( ) => {
You can’t perform that action at this time.
0 commit comments