Skip to content

Commit

Permalink
Make dynamic wasm module example clearer
Browse files Browse the repository at this point in the history
  • Loading branch information
RoyalIcing committed Aug 17, 2023
1 parent 1b0455d commit 139b71f
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions test/dynamic_test.exs
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
defmodule DynamicTest do
use ExUnit.Case, async: true

defmodule UserInfo do
def user_id() do
Process.get(:user_id)
defmodule CurrentUser do
def get_id() do
Process.get(:user_id) || raise "User ID must be set."
end

def user_type() do
def get_type() do
Process.get(:user_type, :viewer)
end
end

# SLIDE

defmodule DynamicA do
use Orb

# defw can_edit?(post_id: I32, author_id: I32), I32

wasm do
case UserInfo.user_type() do
case CurrentUser.get_type() do
:admin ->
func can_edit?(post_id: I32, author_id: I32), I32 do
1
end

:viewer ->
func can_edit?(post_id: I32, author_id: I32), I32 do
author_id === UserInfo.user_id()
author_id === inline(do: CurrentUser.get_id())
end
end
end
Expand Down

0 comments on commit 139b71f

Please sign in to comment.