Extract autosave timer scheduling from App.vue#88
Merged
Conversation
Moves the idle-autosave timer mechanics for local drafts and Android documents into a createAutosaveScheduler factory in features/document-session: per-target scheduling with debounced rescheduling, cancellation, the autosave/localDrafts guard predicates, and the mid-session resync applied when document settings change (disable clears pending timers; re-enable or a delay change reschedules a dirty document for its current target). The save workflows are untouched and injected as plain triggers, per the TODO constraint. App destructures the same function names, so every existing call site (editor sync, save entry points, editor teardown, draft flows) is unchanged, and the settings watch body becomes a one-line delegation. The only mechanical difference is bare setTimeout/clearTimeout instead of the window-prefixed forms, which is behavior-identical in the WebView and makes the module testable under fake timers.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Third PR of the semantic-decomposition series: moves the idle-autosave timer mechanics out of
App.vueinto acreateAutosaveSchedulerfactory infeatures/document-session. Behavior-preserving; per the TODO constraint, the actual save workflows are not touched — they are injected as plain triggers.Boundary
The scheduler owns:
canRunIdleLocalDraftAutosave= autosave + local-drafts setting;canRunIdleAndroidDocumentAutosave= autosave), exported because editor-sync status text in App still consults them,documentSettingswatch: disabling local drafts clears the draft timer, disabling autosave clears both, and re-enabling autosave or changing the delay reschedules a dirty document for its current target while actively editing.App destructures the same function names, so every existing call site (editor sync scheduling, the save entry points clearing their own timer, editor teardown, draft flows) is textually unchanged, and the settings watch body becomes a one-line delegation. State stays in App and is passed as refs; editing-activity is a getter.
One mechanical note: the module uses bare
setTimeout/clearTimeoutinstead of the previouswindow.-prefixed forms — identical behavior in the WebView, and it lets the module run under fake timers in tests.Testing
autosaveScheduler.test.ts(8 tests, fake timers): exact-delay firing, debounced rescheduling, per-target guards, cancellation, disable-clears-both, delay-change rescheduling a dirty Android document, re-enable scheduling a dirty draft, and no-op when not actively editing.mobile-local-draft-lifecycle(editor-input autosave, the four lifecycle flush paths, back-button prompt),mobile-android-document-lifecycle(save-failure recovery, read-only flows),mobile-documents-settings(local-draft setting disabled).