Skip to content

Events: e.value is nil for Dropdown, Chip and PopupMenuButton select; zero-parameter lambda handlers raise; Flashlight#on hides Control#on; View, Dismissible, Pagelet and KeyboardListener lack Flet's confirm, drawer and focus methods #149

Open

Description

@AdamMusa

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" to 2.

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_event and the Dropdown Material 2 handler wrapper (platform_control_contracts.rb) all call handler.call(event).
  • The same happens with method(:refresh) when refresh takes no parameters.
  • A one-parameter lambda and a zero-parameter proc both 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)
  • View and Pagelet: show_drawer, close_drawer, show_end_drawer and close_end_drawer
  • KeyboardListener.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) and keyboard_listener.focus(timeout: 5) reach Kernel#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.value is the picked key, bool or id for a scalar select payload, as e.data already 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.on and flashlight.on(timeout:, on_result:) still turn the light on.
  • view.confirm_pop(should_pop = true) and dismissible.confirm_dismiss(dismiss = true) exist, as do show_drawer, close_drawer, show_end_drawer and close_end_drawer on View and Pagelet, and keyboard_listener.focus. Each invokes the client method of the same name.

Proposal

  1. In Event#value, when typed_data is an AutoCompleteSelectEvent and the payload is not a Hash, return GenericEvent.from_data(data).value. typed_data stays as it is.
  2. Add Ruflet::Control.call_handler(handler, event), which calls a lambda or Method of arity 0 without the event. Use it in Control#emit, Page#dispatch_page_event and the Material 2 handler wrapper.
  3. Add the methods in section 4 as thin wrappers over runtime_page&.invoke, sending {"should_pop" => bool} and {"dismiss" => bool}, with specs in test/support/method_contracts.
  4. Flashlight#on(*event_name, timeout:, on_result:) is Control#on when 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions