File tree 2 files changed +20
-2
lines changed
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) {
334
334
335
335
const cache = reactorState . get ( 'cache' )
336
336
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 ) {
339
339
cacheEntry = createCacheEntry ( reactorState , keyPathOrGetter )
340
340
}
341
341
Original file line number Diff line number Diff line change @@ -595,6 +595,24 @@ describe('Reactor', () => {
595
595
expect ( taxPercentSpy . calls . count ( ) ) . toEqual ( 2 )
596
596
expect ( subtotalSpy . calls . count ( ) ) . toEqual ( 1 )
597
597
} )
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
+ } )
598
616
} )
599
617
600
618
describe ( '#observe' , ( ) => {
You can’t perform that action at this time.
0 commit comments