Created
February 19, 2024 23:20
-
-
Save jechol/4461a73472983e15158665c4994ede75 to your computer and use it in GitHub Desktop.
flow vs function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
flow do | |
# Flow arguments allow you to parameterize the flow | |
argument :org_name, :string do | |
allow_nil? false | |
end | |
argument :user_name, :string do | |
allow_nil? false | |
end | |
# The flow returns the result of the `:create_user` step. | |
returns :create_user | |
end | |
steps do | |
# The step is called `:create_org`, and it creates an `Organization` using the `register_org` action. | |
create :create_org, MyApp.Accounts.Organization, :register_org do | |
# The input to the action refers to an argument of the flow | |
input %{ | |
name: arg(:org_name) | |
} | |
end | |
# The step is called :create_user, and it creates a `User` using the `:register_user` action. | |
create :create_user, MyApp.Accounts.User, :register_user do | |
input %{ | |
# The input refers to an argument of the flow | |
name: arg(:user_name), | |
# and to the result of another step | |
org: result(:create_org) | |
} | |
end | |
# The step is called :create_blank_project, and it creates a `Project` using the `:create_example` action. | |
create :create_blank_project, MyApp.Accounts.Project, :create_example do | |
input %{ | |
# The input refers to the result of another step | |
org: result(:create_org) | |
} | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def create_user(org_name, user_name) do | |
org = MyApp.Accounts.Organization.register_org(org_name) | |
user = MyApp.Accounts.User.register_user(user_name, org) | |
MyApp.Accounts.Project.create_example(org) | |
user | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment