phoenixframework / phoenix_live_view

Rich, real-time user experiences with server-rendered HTML
https://hex.pm/packages/phoenix_live_view
MIT License
6.1k stars 910 forks source link

Lacking a way to compose a `JS` instance from more than two other `JS` instances #3233

Open DaTrader opened 4 months ago

DaTrader commented 4 months ago

There's a use case with a pipe of three JS structs where the middle one is not known upfront and is supplied as a parameter to the function, ex:

defp make_sandwich( path, inner_js, push_opts) do
  JS.dispatch( "replace-state", detail: %{ path: path})
  |> JS.pipe( inner_js)
  |> JS.push( "do_something_useful", push_opts)
end

If the JS type wasn't opaque, we could do the above ourselves i.e.

defp pipe( first, second) do
  %JS{ first | ops: first.ops ++ second.ops}
end

But since it is opaque, it'd be of great help if the pipe function was added to JS module.

DaTrader commented 4 months ago

PS: I'll make a PR myself if I have a blessing from the core team to add this feature.