Let’s say I have a liveview
defmodule MyLiveview do
...
def mount(_, _, socket) do
...doing something
{:ok, socket}
end
def handle_params(_, _, socket) do
socket
...
|> assign(:data, get_data(socket))
end
def get_data(socket) do
socket =
socket
|> assign(data: some_data)
{:noreply, socket}
end
end
I want to create another liveview that does all the same things except i want to change how get_data/1
puts the data on assigns. so I basically want to use MyLiveview
and defoveridable
get_data/1
in this new liveview MyLiveView.AnotherOne
. but if i wrap MyLiveview
in
defmacro __using__(_opts) do
quote do
and use MyLiveview
in MyLiveView.AnotherOne
it no longer works for the route that uses MyLiveview
but works fine for MyLiveView.AnotherOne
. So, how can I use all the functions from one liveview while overriding some? Basically I have a use case for a liveview that acts exactly like another liveview except for one small aspect in how data is fetched and I dont want to maintain 2 liveviews with 95% the same code. Any suggestions would be greatly appreciated!