I hereby claim:
- I am benvp on github.
- I am benvp (https://keybase.io/benvp) on keybase.
- I have a public key ASA67CkwGjbTJnmroRS0FqsrYFm5aVggYrJba_M35IUbrQo
To claim this, I am signing this object:
def reload(item) do | |
%struct{} = item | |
pk = struct.__schema__(:primary_key) |> List.first | |
%{^pk => id} = item | |
get(struct, id) | |
end | |
def max(queryable, fieldName) do | |
query = from x in queryable, | |
select: max(field(x, ^fieldName)) |
I hereby claim:
To claim this, I am signing this object:
// 20190506104306 | |
// https://gist.githubusercontent.com/benlime/ae8087466b2d969f7916c7425356d1fa/raw/8e51a731c232af378db0557f3e8ad5765e61d671/extensions.json | |
[ | |
{ | |
"metadata": { | |
"id": "beb66794-aacf-4696-937a-465e2f9508c5", | |
"publisherId": "myax.appidocsnippets", | |
"publisherDisplayName": "myax" | |
}, |
# in your phoenix project dir | |
cd assets | |
yarn add alpinejs |
import 'alpinejs'; | |
// ... | |
let liveSocket = new LiveSocket('/live', Socket, { | |
dom: { | |
// make LiveView work nicely with alpinejs | |
onBeforeElUpdated(from, to) { | |
if (from.__x) { | |
window.Alpine.clone(from.__x, to); |
defmodule Autocomplete.Items do | |
@items [ | |
%{id: 1, name: "Item 1", image_url: "images/items/1.png"}, | |
%{id: 2, name: "Item 2", image_url: "images/items/2.png"}, | |
%{id: 3, name: "Item 3", image_url: "images/items/3.png"}, | |
%{id: 4, name: "Item 4", image_url: "images/items/4.png"} | |
] | |
def list_items() do | |
@items |
defmodule AutocompleteWeb.ItemSearchLive do | |
use AutocompleteWeb, :live_view | |
alias Autocomplete.Items | |
def mount(_params, _session, socket) do | |
items = Items.list_items() | |
{:ok, assign(socket, suggestions: items, selected: [])} | |
end |
scope "/", AutocompleteWeb do | |
pipe_through :browser | |
live "/", ItemSearchLive, :index | |
end |
<div class="container"> | |
<h2>Item search</h2> | |
<script> | |
// we add a global autocomplete function | |
// which will handle our client-side logic. | |
// we extend this later on... | |
function autocomplete() { | |
return { | |
isOpen: false, |
def handle_event("suggest", %{"search" => search}, socket) do | |
suggestions = Items.list_items() |> suggest(search) | |
{:noreply, assign(socket, suggestions: suggestions)} | |
end | |
defp suggest(items, search) do | |
Enum.filter(items, fn i -> | |
i.name | |
|> String.downcase() |