Closed carson-katri closed 1 year ago
I'm currently working on a new macro implementation that takes the value type explicitly, since more complex types are needed for MultiDatePicker
This could also provide options for a Binding animation:
native_binding :my_bool, :boolean, default: false, animation: :default
Hmm, binding animations are interesting. I think they should be specified somehow where the binding is used, rather than where it's declared? The declaration is really more like @State
, and so using it in a template would be analogous to passing $myStateProp.animation(.default)
into another view.
And also keeping the animation option at the use-site would let rest of the backend bindings support be platform-agnostic.
Currently, there is no macro available in the Elixir library that allows you to create a live binding. However, they are necessary for features of certain Views like
TextEditor
andList
.A `bindings` macro was proposed in #164. This could be brought in as-is.
```ex defmacro bindings(names_and_defaults) do quote bind_quoted: [names_and_defaults: names_and_defaults] do on_mount {__MODULE__, :_set_binding_defaults} def on_mount(:_set_binding_defaults, _params, _session, socket) do { :cont, socket |> assign(unquote(names_and_defaults)) |> push_event("_live_bindings", Map.new(unquote(names_and_defaults))) } end Enum.each(names_and_defaults, fn {name, _default} -> def unquote(:"get_#{name}")(socket) do socket.assigns[unquote(name)] end def unquote(:"set_#{name}")(socket, value) do socket |> assign(unquote(name), value) # todo: it would be nice if there were a hook that let us coalesce multiple changes in a single callback into one event |> push_event("_live_bindings", %{unquote(name) => value}) end def handle_event(unquote(to_string(name)), %{"value" => value}, socket) do {:noreply, assign(socket, unquote(name), value)} end end) end end ```Alternatively, one could be designed that allows for more detailed information to be specified per binding:
fyi @shadowfacts @supernintendo