LvStates.WithSearch (lv-states v0.1.1) View Source
LvStates.WithSearch adds a :search subset of state
to the main LiveView.Socket.
It is useful in situations where we want our application to
query our data most typically stemming from a client search input.
Using the LvStates.WithSearch macro will have two consequences for our LiveView.Socket:
It is populated with a
:searchfield containing%{searching: false, query: nil}.A new event handler is generated:
def handle_event("search-model", %{"query" => query}, socket)
And lastly an indirect consequence is that LvStates.WithSearch assumes that our LiveView implements the following method:
def fetch(%LiveView.Socket{})Note: if the assumed fetch/1 function is not implemented the functionality will not work as expected.
Examples
defmodule CarInventory do
use LvStates.WithSearch, [:model]
end