Repository navigation
refactor: dispatch Page invoke methods through a handler table (WP-00 R4) - #103
Merged
AdamMusa merged 2 commits intoNov 8, 2026
Merged
Conversation
Ruby reaches the Page control (wire id 1) through invoke(:page, ...), page.get_device_info and page.set_allowed_device_orientations. Pin, on both designs, the exact invoke_control_method reply for each method the Page handles (push_route, get_device_info, set_allowed_device_orientations, take_screenshot with and without enable_screenshots), the error replies for missing or bad arguments and for desktop orientations, and the "Exception: Unknown Page method: <name>" reply an unhandled name gets within one frame instead of waiting for the Ruby timeout. Also pin the "Page.<name>(<args>)" log line. These pass on the current switch-based dispatch; the handler table that replaces it must keep them green.
WP-00 R4. The Page control answered Ruby's invoke_control_method with one
switch, so every feature that adds a Page method (take_screenshot sugar,
image-cache methods, system UI) would edit the same lines. Replace it with
a name -> handler map: each method is its own handler and a new one is one
map entry plus its function.
Behavior is unchanged: the same "Page.<name>(<args>)" log line, the same
handlers (bodies moved verbatim), the same results and errors, and a name
with no handler still throws Exception("Unknown Page method: <name>") at
once, so Ruby gets the error reply immediately instead of waiting out its
timeout. Handlers run synchronously up to their first await, as the switch
cases did, so push_route still moves the route before the reply is sent.
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.
What
WP-00 R4, engine half. The Page control (
lib/src/controls/page.dart,_PageControlState) answered Ruby'sinvoke_control_methodwith oneswitch. It now dispatches through a name → handler map:Each case body moved verbatim into its own handler.
_invokeMethodstill writes thePage.<name>(<args>)log line, looks up the handler, and throwsException("Unknown Page method: <name>")when there is none.Why
Wave 1 and wave 2 packages add Page methods: RT-04
take_screenshotsugar, RT-05 system UI, and the WP-18 image-cache methods. With a switch, every one of them edits the same lines. With the map, each new method is one map entry plus one function. The Ruby half (appendable page props, Page events and page methods) is AdamMusa/ruflet#74.Proof of zero change
caseinto aFuture<dynamic>handler:breakbecomesreturn nullandcasebecomes a method.await, as itscasedid. Sopush_routestill moves the route before the reply is sent.Exception: Unknown Page method: <name>. It arrives within one frame while the Ruby timeout (30 s in the test) is never advanced.test/widgets/page_invoke_methods_test.dartis its own first commit (935c9e87), and it passes on the switch-based code (10/10). It also passes unchanged on the refactor.packages/ruflet):flutter test:+2291: All tests passed!at935c9e87(old switch plus the new test) and+2291: All tests passed!at the head3dc4a56c.flutter analyze:No issues found!infolints, all invendor/flutter_math_forkandvendor/flutter_markdown_plus.push_routeentry or throwing a different error type for unknown names fails 4 of the new tests.RenderRepaintBoundary.toImage,SystemChrome.setPreferredOrientations).test/contract/ruflet_control_surface.jsonneeds no update.Behavior changes
None.
Tests
test/widgets/page_invoke_methods_test.dart(10 tests: 5 cases × Android and iOS designs). It drives a connected backend through a recording channel and asserts the exactinvoke_control_methodreply Ruby receives for each method:no_such_method,Push_Route(names match exactly), the empty name, andshow_drawer(a View method, not a Page method). Each returnsException: Unknown Page method: <name>within one frame. The log linePage.no_such_method({})is still written.push_route:{}orroute: nil, the reply isInvalid argument(s): Page.push_route requires a "route" argument./next, the reply isresult: null, error: null, the backend route changes, and the log line is written.get_device_info: returns the record and ignores extra args. A failing source givesBad state: no record.set_allowed_device_orientations:[]and nil (all orientations) reachSystemChrome.setPreferredOrientations.Invalid argument (orientations): Page.set_allowed_device_orientations: unknown orientation: "sideways".Unsupported operation: set_allowed_device_orientations is only supported on mobile platforms, and no platform call is made.take_screenshot: returnsnullwithoutenable_screenshots, and PNG bytes with it.Not in this PR
Users get this only through a later
ruflet-templatesync (ruby tool/sync_ruflet_source.rb --source ruflet-engine --ref <sha>, X3).