Repository navigation
Description
Found during an audit of main (a668af6), against ruflet-engine codex/engine-initialization (00d1df3c) and ruflet-template main (8b08569). Every case below was reproduced in-process with Ruflet::Page, replaying the client's real order: apply_client_update, then dispatch_event.
1. event.value is nil for every select event except AutoComplete's
GestureEventFactory (events/gesture_events.rb) maps every "select" to AutoCompleteSelectEvent. Its from_data reads only a Map payload, and turns any other payload into raw = {} and value = nil.
The other controls that fire select send a scalar:
| Control | Renderer | Payload |
|---|---|---|
| Dropdown | material_dropdown.dart (after it syncs value); the Cupertino sheet in cupertino_input_controls.dart |
the option's key, as a String |
| Chip | material_chip.dart; cupertino_content_controls.dart |
the new selected bool |
| PopupMenuButton | material_popup_menu_button.dart; cupertino_navigation_controls.dart |
the item's id, as a String |
| AutoComplete | material_auto_complete.dart |
{"index", "selection"} |
| Case | e.data |
e.value (today) |
|---|---|---|
Dropdown, String keys, pick "b" |
"b" |
nil |
Dropdown, Integer keys, pick 2 |
2 |
nil |
dropdown_m2(on_change:) |
"blue" |
nil |
| Chip | true |
nil |
| PopupMenuButton | the item id | nil |
| AutoComplete (Map payload) | the Map | "v" (correct) |
The compatibility tests do not catch this. dropdown_compatibility_test.rb, chip_compatibility_test.rb and popup_menu_compatibility_test.rb assert event.value, but they send { "value" => ... }, a Map the client never sends.
Do not fix this in AutoCompleteSelectEvent.from_data. Page#apply_event_value_to_control writes a select's typed value into the control's props. If from_data returned the scalar:
- a PopupMenuButton would gain a
"selected" => <id>prop, and the next full patch would send it; - on an Integer-key Dropdown,
e.control.props["value"]would change from the synced"2"to2.
2. A handler that takes no parameters raises on every event
button("Save", on_click: -> { save! })This raises ArgumentError: wrong number of arguments (given 1, expected 0) on every click.
Control#emit,Page#dispatch_page_eventand the Dropdown Material 2 handler wrapper (platform_control_contracts.rb) all callhandler.call(event).- The same happens with
method(:refresh)whenrefreshtakes no parameters. - A one-parameter lambda and a zero-parameter
procboth work. - Flet calls a handler that takes no parameters without the event (
base_control.py).
3. Flashlight#on hides Control#on
current_service_methods.rb defines on(timeout: 10, on_result: nil) on FlashlightControl, which turns the light on. Flet's name for that method is on. This hides Ruflet::Control#on(event_name, &block), so flashlight.on(:error) { |e| ... } raises ArgumentError (given 1, expected 0). The workaround is the on_error: keyword.
4. View, Dismissible, Pagelet and KeyboardListener lack Flet's methods
Flet v1.1.2 has these methods. The renderers handle them (view.dart, dismissible.dart, pagelet.dart, keyboard_listener.dart), but Ruflet has no Ruby method for any of them:
View.confirm_pop(should_pop)Dismissible.confirm_dismiss(dismiss)ViewandPagelet:show_drawer,close_drawer,show_end_drawerandclose_end_drawerKeyboardListener.focus
view.dart and dismissible.dart wait for confirm_pop and confirm_dismiss. Without an answer, the client keeps the view or the item after 5 minutes. The documented workaround works today:
page.invoke(e.control, "confirm_pop", args: { should_pop: true })A natural call silently does nothing:
view.confirm_pop(no arguments) raises NoMethodError.view.confirm_pop(true),dismissible.confirm_dismiss(true)andkeyboard_listener.focus(timeout: 5)reachKernel#method_missing. Because the receiver is a Ruflet object, it builds an unused generic control (type"confirm_pop","confirm_dismiss","focus") and sends nothing to the client.
Expected
e.valueis the picked key, bool or id for a scalar select payload, ase.dataalready is.e.data,typed_data, the props the client synced and every later patch are unchanged.- A lambda or Method that takes no parameters runs without the event. Every other handler still gets the event.
flashlight.on(:error) { ... }registers the handler.flashlight.onandflashlight.on(timeout:, on_result:)still turn the light on.view.confirm_pop(should_pop = true)anddismissible.confirm_dismiss(dismiss = true)exist, as doshow_drawer,close_drawer,show_end_drawerandclose_end_draweron View and Pagelet, andkeyboard_listener.focus. Each invokes the client method of the same name.
Proposal
- In
Event#value, whentyped_datais anAutoCompleteSelectEventand the payload is not a Hash, returnGenericEvent.from_data(data).value.typed_datastays as it is. - Add
Ruflet::Control.call_handler(handler, event), which calls a lambda or Method of arity 0 without the event. Use it inControl#emit,Page#dispatch_page_eventand the Material 2 handler wrapper. - Add the methods in section 4 as thin wrappers over
runtime_page&.invoke, sending{"should_pop" => bool}and{"dismiss" => bool}, with specs intest/support/method_contracts. Flashlight#on(*event_name, timeout:, on_result:)isControl#onwhen given an event name. Otherwise it keeps turning the light on.
Docs note for ruflet_site, after the next release: control_dropdown.md and config/property_descriptions.json (Dropdown on_select) say event.value is nil for this event. control_dismissible.md documents the page.invoke reply, which event.control.confirm_dismiss(true) would replace.
Activity