Skip to content

Extract current-document persistence actions from App.vue#89

Merged
Renakoni merged 1 commit into
mainfrom
refactor/current-document-persistence
Jul 10, 2026
Merged

Extract current-document persistence actions from App.vue#89
Renakoni merged 1 commit into
mainfrom
refactor/current-document-persistence

Conversation

@Renakoni

Copy link
Copy Markdown
Owner

Summary

Fourth PR of the semantic-decomposition series: moves every way the current editor document is persisted or exported out of App.vue into a createCurrentDocumentPersistence factory in features/document-session. Behavior-preserving; the save/share workflows and document-state transitions are reused unchanged, per the TODO.

Boundary

The factory owns:

  • Local-draft autosave (saveDraft) with its target/setting guards and status transitions.
  • Android document save (saveAndroidDocument) including the in-flight coalescing flags (a save requested during a save re-schedules once the first completes, preserving the changed-during-save path) and the read-only/missing-source/clean short-circuits.
  • Draft-to-device save and save-a-copy flows with their cancel/transient/saved/failed branches, busy flags, and exit-prompt interplay.
  • Sharing the current document with its busy guard.
  • Lifecycle flush routing to the save path matching the current autosave target.
  • Recovery-draft bookkeeping (persist with the setting guard, removal) and recents saved-marking — the latter stays private to the module since its only caller is the Android save path.

Everything App owns is injected: state refs (document state, status, notices, busy flags, prompt flags, stores), editor access (hasEditor, snapshot, sync), chrome closers, predicates and presentation helpers, store persistence + rememberAndroidDocument (shared with the open paths, so it stays in App), the autosave-scheduler timer handles, natives, settings refs, and loggers. App destructures the same function names — every call site (exit prompts, editor menu/actions sheet, incoming-document orchestration, lifecycle flush) is textually unchanged.

One wiring note: the autosave scheduler now receives saveDraft/saveAndroidDocument as deferred closures, because the two factories reference each other's handles (scheduler triggers saves; saves clear/reschedule timers) and const initialization order would otherwise TDZ.

App.vue shrinks by ~400 lines.

Testing

  • New currentDocumentPersistence.test.ts (12 tests) drives the real save/share/copy workflows with mocked natives: draft autosave success + skip guards, Android save success updating recents and dropping the recovery draft, save failure keeping a recovery draft (and the users-message fallback when recovery drafts are disabled), in-flight coalescing with post-completion rescheduling, flush routing and its screen guard, draft-to-device saved/canceled-reopens-prompt paths, save-a-copy clearing the exit prompt and the original recovery draft, share success and the busy guard.
  • Full unit suite 296/296, ESLint, vue-tsc, production build green.
  • Contract E2E 28/28: mobile-local-draft-lifecycle (autosave + all four lifecycle flush paths), mobile-android-document-lifecycle (save-failure recovery, read-only exit flows), mobile-android-document-actions (save-copy variants, transient access), mobile-share-intent (current-document share paths).

Moves every way the current editor document is persisted or exported
into a createCurrentDocumentPersistence factory in
features/document-session: local-draft autosave, Android document save
with its in-flight coalescing flags, draft-to-device save, save-a-copy,
sharing, lifecycle flushes, and the recovery-draft plus recents
bookkeeping around them (recents marking stays private to the module;
its only caller is the Android save path).

The existing save/share workflows and document-state transitions are
reused unchanged. App destructures the same function names so all call
sites — exit prompts, editor menu, incoming-document orchestration, and
lifecycle flush — are textually unchanged. The autosave scheduler now
receives its two save triggers as deferred closures because the two
factories reference each other's handles.
@Renakoni Renakoni merged commit c45ff04 into main Jul 10, 2026
5 checks passed
@Renakoni Renakoni deleted the refactor/current-document-persistence branch July 10, 2026 11:59
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