Skip to content

v0.19.0

Choose a tag to compare

@ioquatix ioquatix released this 07 Sep 07:09
· 9 commits to main since this release
3065d78

Explicit Element Construction

Element construction now separates serialized element data from Ruby constructor options and makes the intended construction path explicit.

  • Live::Element#initialize now requires both id and data. Replace MyView.new with MyView.root, and replace MyView.new("custom-id") with MyView.root("custom-id"). Internal callers using new directly must pass the data hash explicitly, even when empty.
  • Live::Element.root, .child, and .mount now accept serialized attributes through data:. Other keyword arguments are forwarded to initialize. For example, change MyView.root(mode: "presenter") to MyView.root(data: {mode: "presenter"}); constructor dependencies such as controller: can remain ordinary keyword arguments.
  • Calls passing a positional data hash to .mount must use the data: keyword. Change ChildView.mount(parent, "child", {mode: "compact"}) to ChildView.mount(parent, "child", data: {mode: "compact"}).
  • Live::Resolver#root(view_class, id = view_class.unique_id, data: {}, **options) constructs an allowed root using the same internal path as browser-resolved elements. Custom resolvers that inject dependencies can override the private make(view_class, id, data, **options) method instead of overriding call.