mirror of
https://github.com/olehomelchenko/astrolabe.git
synced 2026-08-08 02:02:33 +00:00
Snippet naming: content-derived on publish, frozen on explicit rename
This commit is contained in:
@@ -165,6 +165,20 @@ const active = useSnippetStore(selectActiveSnippet);
|
||||
> Rule: if you can compute it, do not store it. Add a new state field only for a
|
||||
> value that is _input_ the app receives, not output it derives.
|
||||
|
||||
### Editing buffers — the sanctioned duplication, and its sync rule
|
||||
|
||||
A text field with debounced auto-save (the metadata panel's Name/Comment, the editor
|
||||
buffer) legitimately mirrors a store fact into local component state: the local copy is
|
||||
the user's in-progress text, the store holds the saved value. This duplication carries an
|
||||
obligation the moment the store fact has **another writer** (publish's content-derived
|
||||
renaming, import, any store-side mutation): the component must **adopt** a store change it
|
||||
didn't make, or its debounced save will write the stale local copy back — silently undoing
|
||||
the other writer. The pattern (see `SnippetLibrary`'s `SnippetMeta`): track the last store
|
||||
value seen in a ref; when the store value changes, adopt it into local state **unless the
|
||||
user has diverged** (local ≠ previous store value) — in-progress typing always wins.
|
||||
Keying the component by entity id handles switching entities; this rule handles the same
|
||||
entity changing underneath.
|
||||
|
||||
---
|
||||
|
||||
## 3. Where State Lives: Central vs. Per-Feature Stores
|
||||
|
||||
Reference in New Issue
Block a user