Skip to content

broadcast_poke error while sending to something else than a socket #141

@grych

Description

@grych
iex(6)> broadcast_poke same_path("/tests/live/mini"), color: "red"
** (ArgumentError) argument error
    :erlang.apply("same_path:/tests/live/mini", :assigns, [])
    (drab) lib/drab.ex:646: Drab.get_view/1
    (drab) lib/drab/live.ex:441: Drab.Live.do_poke/5

This is because Drab.Live in general requires connection to the browser, as it is getting the current assigns from there.

There are three available solution for this

  1. Remove broadcast_poke. Initially, I did not plan to implement it, changed my mind because of Allow to broadcast using poke / peek #60

  2. Allow broadcast_poke only with connected socket, create a good error message and fix a documentation (remove "all broadcasting functions may have socket or... as an argument").

  3. While broadcasting to non-socket, force to provide all the assign values. In this case there is no need to read the assign values from the browser.
    The only thing is a problematic API, we need to provide the list of other assign values somehow.

broadcast_poke same_path("/"), color: "red", using_assigns: [text: "text",..]

But in this case you can't name you assign @using_assigns :) Any other suggestions?

Personally, I like 1st solution the most :) But 3rd may also do the trick, with good error message when not all the assign values are provided.

Additionally, we could implement 3rd solution also in poke - if you provide all the values there is no need to read it from the browser, which improves the performance, especially when having partials with one assign only.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions