LiveX
is a work-in-progress library for handling State
changes in a Phoenix LiveView application according to the Flux pattern.
The current implementation is heavily inspired by the Vuex project.
- Copy the logic of the store.ex file into your Project.
- Add the line
defdelegate handle_info(msg, socket), to: Store
to anyLiveView
controller in which you want to useStore
. - In your parent/root/outermost
LiveView
instance initiate the Store with{:ok, Store.init(socket)}
in themount/2
function. - In any child
LiveView
instance, join theStore
instance with{:ok, Store.join(params, socket)}
. - Initiate any
State
changes with theStore.dispatch/2
function. - Use the state in your
.leex
templates with@state.your_variable
- Compare the performance of storing all variables in a single
state
assignment vs. splitting up the variables into separate assignments.