Services

Clipboard

Clipboard service

Create or retrieve this service with page.clipboard(**properties). Ruflet reuses the registered service unless you supply a different id.

Example

result = text(value: "Nothing copied yet")
page.add(result)
page.set_clipboard("Copied from Ruflet", on_result: ->(_saved, save_error) {
  next page.update(result, value: save_error.to_s) if save_error

  page.get_clipboard(on_result: ->(value, read_error) {
    page.update(result, value: read_error ? read_error.to_s : value.to_s)
  })
})

Page accessor

  • page.clipboard(**props)

Properties

  • data — Arbitrary value you can attach to the control and read back in handlers.
  • key — Stable identity used to preserve state across rebuilds.

Service methods

  • get(timeout: ..., on_result: ...)
  • get_files(timeout: ..., on_result: ...)
  • get_image(timeout: ..., on_result: ...)
  • set(value, timeout: ..., on_result: ...)
  • set_files(files, timeout: ..., on_result: ...)
  • set_image(value, timeout: ..., on_result: ...)

Page convenience methods

Use these one-shot Page calls when you do not need to keep the service object:

  • page.set_clipboard(value, timeout: ..., on_result: ...)
  • page.get_clipboard(timeout: ..., on_result: ...)
  • page.set_clipboard_files(files, timeout: ..., on_result: ...)
  • page.get_clipboard_files(timeout: ..., on_result: ...)
  • page.set_clipboard_image(value, timeout: ..., on_result: ...)
  • page.get_clipboard_image(timeout: ..., on_result: ...)

Result and error handling

Client calls are asynchronous. When a method accepts on_result:, handle both callback values: |result, error|. Availability and returned data can vary by platform.

Common service API

The service also supports the common Ruflet control API: attach_handler(event_name, handler), children, emit(event_name, event), has_handler?(event_name), id, merge_props(values = ...), on(event_name, &block), props, runtime_page, runtime_page=, to_patch, type, wire_id, wire_id=.

Use the named methods above for application code; common control methods mainly support event registration, updates, and runtime integration.

Wire reference

  • Service helper: clipboard
  • Wire type: clipboard