Skip to content

feat: add onStart/onStop/onSaved/onError callbacks to autosave options#751

Open
ascott18 wants to merge 1 commit into
mainfrom
ascott18-autosave-callback-options
Open

feat: add onStart/onStop/onSaved/onError callbacks to autosave options#751
ascott18 wants to merge 1 commit into
mainfrom
ascott18-autosave-callback-options

Conversation

@ascott18

Copy link
Copy Markdown
Collaborator

Why

Deep auto-saves attach and detach auto-save from entities as they enter and leave the object graph (new navigation properties, loaded collections, $addChild). Today there's no central place to observe the save lifecycle of each individual entity, so reacting to a successful/failed save or knowing when auto-save was attached to a nested entity requires wiring $save.onFulfilled/onRejected on every entity by hand.

What

Adds four optional callbacks to AutoSaveOptions (usable from both $startAutoSave and $useAutoSave, on item and list view models):

  • onStart(vm) - invoked per entity as auto-save attaches, including entities attached to the graph after start.
  • onStop(vm) - invoked when auto-save deactivates (explicit $stopAutoSave() or component unmount).
  • onSaved(vm) - invoked after a successful auto-save $save.
  • onError(vm, error) - invoked when an auto-save $save fails.

Each callback receives the affected view model, which is essential under deep since a single options object is shared across the whole graph.

Notes for reviewers

  • onError fires only on actual $save rejections. Saves skipped due to client validation errors (already observable via $hasError) or a predicate do not invoke it, since no save is attempted.
  • Consistent with existing behavior, $stopAutoSave() is not recursive: stopping a deep root only fires onStop for the root. On component unmount, onStop fires for every entity. This is documented in the callback doc comments and the ViewModels docs.
  • Callbacks fire on actual entities, not on the ListViewModel container (a list never saves; its items each fire their own).

Includes 6 new unit tests covering start/stop/saved/error for both shallow and deep cases, plus CHANGELOG and documentation updates. Full coalesce-vue suite passes (683 tests).

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant