Repository navigation
[RFC] feat(viewer)!: tell openers with events instead of callbacks - #130
Merged
Merged
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #130 +/- ##
==========================================
+ Coverage 92.82% 92.97% +0.15%
==========================================
Files 47 49 +2
Lines 4069 4172 +103
Branches 813 816 +3
==========================================
+ Hits 3777 3879 +102
- Misses 273 274 +1
Partials 19 19 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
skjnldsv
marked this pull request as ready for review
October 8, 2026 09:00
skjnldsv
force-pushed
the
feat/viewer-events
branch
from
October 8, 2026 09:12
4e76ec8 to
9a5cd8d
Compare
skjnldsv
force-pushed
the
feat/viewer-events
branch
2 times, most recently
from
October 8, 2026 12:23
b3c36da to
4e76ec8
Compare
Handlers tell the viewer with events on their element, and the viewer tells them with props. Its openers were the odd one out, with onPrev, onNext, onClose and onEditingChange callbacks in the open options, and the viewer app's downloadCallback, which Text used to save edits before a download, had no equivalent at all. open(), openFolder() and compare() now resolve with a session, an EventTarget that dispatches `update:file`, `update:editing` and `close`, shaped like what handler elements emit. The file shown and editing reach the latest opening only, closing every opening since the viewer opened, as the callbacks did. The viewer itself (getViewer()) dispatches the same events for any page. Before its own Download, Ctrl+S and the Files download action, the viewer dispatches `before-download` on the handler's element, the session and the viewer. What they hand `waitUntil()` holds the download, and a promise that rejects cancels it, with an error. The Files history follows the latest opening it made only: the Files app opens the same file again as the sidebar opens, and both openings hear the viewer close. BREAKING CHANGE: the onPrev, onNext, onClose and onEditingChange options are gone; listen to the session open() resolves with. Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: John Molakvoæ <14975046+skjnldsv@users.noreply.github.com>
skjnldsv
force-pushed
the
feat/viewer-events
branch
from
October 8, 2026 12:25
4e76ec8 to
c446c33
Compare
mejo-
approved these changes
Oct 8, 2026
mejo-
left a comment
There was a problem hiding this comment.
Code changes look good, and indeed much cleaner interface than before.
This was referenced Oct 9, 2026
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.
Handlers already talk to the viewer with events on their element (
loaded,errored,update:*). Openers were the odd one out, withonPrev,onNext,onCloseandonEditingChangecallbacks in the open options. The viewer app'sdownloadCallback, which Text used to save unsaved edits before a download, had no equivalent at all. This moves all of it to events, for discussion before 2.0.0 is stable.open(),openFolder()andcompare()resolve with a session, anEventTargetdispatching:detailupdate:file[file]onPrev,onNextupdate:editing[editing]onEditingChangeclose[]onClosebefore-download{ file, waitUntil }downloadCallbackbefore-downloadalso goes to the handler's element, which is where Text's editor and its unsaved state live (nextcloud/text#9349).getViewer()dispatches all four for any page, whoever opened the viewer. The names anddetailshapes match what handler elements emit.I kept what the callbacks did across openings. The file shown and editing only reach the latest opening, the way
onPrev/onNextcame from the current options.closereaches every opening since the viewer opened, the way everyonClosewas kept. The Files history follows only the latest opening it made: the Files app opens the same file again as the sidebar opens, and unwinding the history once per opening ranhistory.go()twice. There's a test for that now.loadMore,enabled,preloadandonInitstay functions, since the viewer needs their answer.This includes #129, which can be closed if this goes in first. It breaks the server's
OCA.Viewershim (apps/viewer/src/legacy.ts), which mapsonPrev,onNextandonCloseto these options and is what Photos goes through. That needs porting with the bump. Text, Whiteboard and the server's other callers don't pass these options. I dropped the test "tells the others when one of them throws", becausedispatchEventalready keeps a throwing listener from stopping the others.Unit and Playwright tests pass locally.
👾 This pull request was assisted by Claude Code, commits carry an
Assisted-bytrailer.