Skip to content

Instantly share code, notes, and snippets.

@myobie
Created June 27, 2017 09:36
Show Gist options
  • Select an option

  • Save myobie/621c93f86d6d9d6c52b4bfb9a6378c57 to your computer and use it in GitHub Desktop.

Select an option

Save myobie/621c93f86d6d9d6c52b4bfb9a6378c57 to your computer and use it in GitHub Desktop.
An example of how users and lists could know about each other
defmodule User do
use Highlander.Object, type: :user
defobject name: "", email: "", known_lists: []
end
defmodule List do
use Highlander.Object, type: :list
defobject title: "", todos: [], allowed_users: []
def handle_update({:insert_todo, list, todo, user}, state) do
if Enum.any?(list.allowed_users,
fn id -> id == user.id end) do
%{todos: [todo | state.todos]}
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment