Repository navigation
fix: give select events their value, run zero-parameter handlers, add Flet's confirm, drawer and focus methods; Flashlight#on(event) registers a handler - #150
Open
AdamMusa wants to merge 4 commits into
Conversation
… Flet's confirm, drawer and focus methods
- Event#value: a select whose payload is not a Map (a Dropdown key, a
Chip's bool, a PopupMenuButton item id) has that payload as its value,
as e.data already does. typed_data is unchanged, so the props the client
synced and later patches are too.
- Ruflet::Control.call_handler calls a lambda or Method of arity 0
without the event, as Flet does; Control#emit, Page#dispatch_page_event
and the Dropdown Material 2 wrapper use it. Every other handler still
gets the event.
- Flashlight#on(event_name) { } is Control#on; without an event name it
still turns the light on.
- view.confirm_pop, dismissible.confirm_dismiss, show_drawer,
close_drawer, show_end_drawer and close_end_drawer on View and Pagelet,
and keyboard_listener.focus invoke the client methods the renderers
already handle.
Fixes #149
…onfirm_dismiss Flet calls View.confirm_pop(should_pop=...) and Dismissible.confirm_dismiss(dismiss=...) by keyword. The positional form keeps working; the keyword wins when both are given. Also pin that flashlight.on(:error) without a block is Control#on.
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.
Fixes #149
Only
ruflet_corechanges. There are no engine, template, wire-format or CLI changes.What changed
1. A select event's
valueis its payload (event.rb)Event#valuenow returns the payload whentyped_datais anAutoCompleteSelectEventand the payload is not a Map. The rule is the same oneGenericEventuses.typed_datais left alone on purpose.Page#apply_event_value_to_controlwrites a select's typed value into props. ChangingAutoCompleteSelectEvent.from_datawould add a"selected"prop to PopupMenuButton, which later patches would send. It would also turn an Integer-key Dropdown's syncedprops["value"]"2"into2.2. Handlers with no parameters run (
control.rb,page.rb,platform_control_contracts.rb)Ruflet::Control.call_handler(handler, event). It calls a lambda or Method of arity 0 without the event, as Flet does.Control#emit,Page#dispatch_page_eventand the Dropdown Material 2on_changewrapper use it.call(event): lambdas with parameters, optional or splat parameters, procs, blocks, Methods with parameters and callable objects.3.
Flashlight#on(current_service_methods.rb)Control#on:flashlight.on(:error) { |e| ... }. Without a block it does whatControl#ondoes on every control: it setson_error, sends one patch and registers no handler.flashlight.on,flashlight.on(timeout:, on_result:)andflashlight.on { }, where the block is still ignored.timeout:oron_result:raises ArgumentError. That call raised before too.4. Flet's methods for View, Dismissible, Pagelet and KeyboardListener
view.confirm_pop(true)orview.confirm_pop(should_pop: true)sends{"should_pop" => bool}. The default is true.dismissible.confirm_dismiss(true)ordismissible.confirm_dismiss(dismiss: true)sends{"dismiss" => bool}. The default is true.show_drawer,close_drawer,show_end_drawerandclose_end_draweron View and Pagelet come from a newDrawerMethodsmodule. Likepage.show_drawer, they take no positional argument.keyboard_listener.focuscomes fromFocusableMethods.timeout:andon_result:and invokes the client method thatview.dart,dismissible.dart,pagelet.dartandkeyboard_listener.dartalready handle, in both the engine and the template.test/support/method_contracts, soMethodContractCoverageTestcovers them.Behavior changes (D6: all are bug fixes)
e.valueinon_selectof a Dropdown,dropdown_m2(on_change:), Chip or PopupMenuButtonnile.dataon_click: -> { ... },method(:no_args),page.on_route_change = -> { ... },flashlight(on_error: -> { ... })flashlight.on(:error) { ... }flashlight.on(:error)with no blockControl#ondoes on every control: returns the flashlight, setson_errorand sends one patch; no handler runsview.confirm_pop,dismissible.confirm_dismiss,view.show_drawer,pagelet.show_drawer(and the close and end variants),keyboard_listener.focusview.confirm_pop(false),view.confirm_pop(should_pop: false),dismissible.confirm_dismiss(false),dismissible.confirm_dismiss(dismiss: false),keyboard_listener.focus(timeout: 5)Kernel#method_missingbuilt an unused generic control (type"confirm_pop", ...), so anon_confirm_poporon_confirm_dismissanswered this way waited 5 minutes and then kept the view or itemview.show_drawer(drawer),pagelet.show_drawer(drawer),keyboard_listener.focus(true),view.confirm_pop(true, false), an unknown keyword such asview.confirm_pop(pop: true)page.show_drawer(drawer)already raises this way. The call never reached the client before, so it now fails loudly instead of doing nothingThe following are unchanged:
e.data,typed_data, event names and the wire;flashlight.onandflashlight.on(timeout:, on_result:);page.invoke(e.control, "confirm_pop", args: ...), the documented workaround, which still works.How it was verified
All runs used Ruby 4.0.5 on this branch (2908091), which merges main 51db9a6.
New tests (fail on main, pass here):
select_event_value_test.rb(7 tests) replays the client's real order and payload shapes. It also asserts that the synced props stay the same and that no"selected"prop reaches a later patch.event_handler_arity_test.rb(7) covers 0-parameter lambdas and Methods on controls, page handlers, services and the Material 2 wrapper. It also checks that 1-parameter, optional and splat lambdas, procs, blocks, 1-parameter and optional Methods and callable objects still get the event.flashlight_on_test.rb(6) andconfirm_and_drawer_methods_test.rb(7). These include the keyword forms andflashlight.on(:error)with no block.control_method_contract_test138 runs on main, 157 here).Bug planted back: I restored each fixed file from main in a copy of this tree, one fix at a time, and ran its test:
event.rbcontrol.rb,page.rband the Material 2 wrappercurrent_service_methods.rbview_control.rbanddismissible_control.rbfrom the previous head (positional only)unknown keywordSuites (one process per test file):
bundle exec)The core skip is the existing
RUFLET_ENGINE_ROOTcheck indsl_presented_controls_test. The rails skips are the existing ones inrails_executor_test.H1 goldens:
cd packages/ruflet && ruby test/compat/compat.rb --jobs 4checked 359 goldens with no diff.compat_goldens_test.rb: 367 runs, 0 failures.mruby:
host_vm.rb) from this tree. A script that drivesPagethrough select values, 0-parameter lambdas, procs and Methods, the Material 2 wrapper,on_route_change, every form offlashlight.onand the new methods with their keyword forms prints ALL OK under it. Under a host VM built from main, the same script fails (select values arenil, then ArgumentError).tools/embedded_vm_harness/tests) give the same output under host VMs built from main and from this branch.ruflet_corefixes.Docs (ruflet_site, after the next release)
app/content/docs/control_dropdown.mdandconfig/property_descriptions.json(Dropdownon_select) sayevent.valueisnilfor this event.control_dismissible.mddocuments thepage.invokereply, whichevent.control.confirm_dismiss(true)would replace.