Frontory

Open code, practice, and notes →

Download source with English comments · for reading

Vue · 18 Shared Store Scope

Series contents · Technology map

Stage: Composables and Store Lifetimes · Editable example · Storage ID: vue-step-18

Goals and learning outcomes

Prerequisites

Unit 18 builds on the work and experiment records from Unit 17.

Key concepts and explanations

Shared reactivity

A module-scope reactive lets multiple components read the same object. Its lifetime differs from a per-component initialization function.

Initialization boundary

Tests or multiple app instances sharing the same module state can mix data. A store factory can make the scope explicit.

Practice setup

First check the execution scope guidance on the example screen. The following is the preparation environment for extending the assignment in a separate project. Use .vue SFCs and script setup in a separate Vue Vite project. Record package versions and the lockfile, and run on the development server. The built-in Vue examples use the h function and are not a general-purpose SFC compiler.

The linked example is a starting point. It does not implement every task below. Complete work beyond its supported scope in a separate project.

Practice tasks

  1. In src/createNotesStore.js, write a function returning drafts, update, and reset.
  2. Create and provide a store for each Workspace.
  3. Enter different strings for the same unit id in two different Workspaces.

Variables to observe

VariableBaselineChangeExpected change / hypothesis
Store creationOne module instanceFactory per WorkspaceDrafts remain separate between the two workspaces even for the same id.

Predictions in this table are not measured results. Change one condition at a time and record why the actual result differs.

Completion criteria

Self-check

  1. Why does moving all state to globals make testing difficult?
  2. How do you separate shared values from per-instance values?

Official references

Linked example and execution scope

Example source · Runtime environments and limits

This is an experiment with actual Vue reactivity and render functions. Check SFC templates in an external compilation environment.

Source code and records are not overwritten automatically. Resetting an existing example also preserves your notes.

Next learning

Previous: provide and inject · Next: Restoring Saved Data and Validation

Open code, practice, and notes →