Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing arguments to call vs using outflow #14

Open
artsyca opened this issue Oct 1, 2019 · 1 comment
Open

Passing arguments to call vs using outflow #14

artsyca opened this issue Oct 1, 2019 · 1 comment

Comments

@artsyca
Copy link

artsyca commented Oct 1, 2019

I'm a bit confused by the ambiguity of passing arguments to call on a Waterfall as opposed to attaching them to the outflow context

Generally the arguments being passed are coming from an outflow anyway, I don't know when to use one over the other

Additionally, it seems each object has its own @outflow property, so passing the outflow as a block is not always needed?

@apneadiving
Copy link
Owner

Hello :)

I feel like it's clearer to separate inputs/outputs:

  • inputs are passed in the initializer
  • outflow is the output

Each waterfall is independent and has its own outflow.
You can get data from another service by grabbing data from its outflow with your desired local name.
Nothing is global or shared per default.

Using or not block params to retrieve outflow is really a matter of context. Lets see this with examples.

If you work with a class, you dont need outflow as block param:

class Services::Registration::AddUser
  include Waterfall

  def initialize(user_params, event_id)
    @user_params = user_params
    @event_id = event_id
  end

  def call
    with_transaction do 
      chain(user: :user) do 
        Services::CreateUser.new(@user_params)
      end
      chain do 
        # here you can access outflow directly as its builtin within the object
        Services::Registration::Subscribe.new(outflow.user, @event_id)
      end
    end
  end
end

But whenever you trigger the flow you need block params. In a controller for instance:

Wf.new
  .chain(user: :user) do 
    Services::Registration::AddUser(user_params, event_id)
  end
  .chain do |outflow| # here you need the outflow from the block
    render json: { user_id: outflow.user.id }
  end
  .on_dam do |error_pool|
    render json: { errors: error_pool }, status: 422
  end

Is it clearer?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants