phoenix_live_view icon indicating copy to clipboard operation
phoenix_live_view copied to clipboard

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

Open DaTrader opened this issue 9 months ago • 1 comments

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 avatar May 07 '24 16:05 DaTrader