Performance: Store-to-store interaction
MEDIUM IMPACT
This affects how quickly and efficiently state changes propagate between different stores, impacting UI responsiveness and rendering speed.
import { useStoreA } from './storeA'; import { useStoreB } from './storeB'; import { watch } from 'vue'; const storeA = useStoreA(); const storeB = useStoreB(); watch(() => storeA.sharedState, (newVal) => { storeB.sharedState = newVal; });
import { useStoreA } from './storeA'; import { useStoreB } from './storeB'; const storeA = useStoreA(); const storeB = useStoreB(); storeA.$subscribe(() => { storeB.sharedState = storeA.sharedState; });
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Direct store subscription | Multiple reactive updates | Multiple reflows per update | High paint cost due to layout thrashing | [X] Bad |
| Using Vue watch for syncing stores | Single reactive update batch | Single reflow per update cycle | Lower paint cost with batched layout | [OK] Good |