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

Add callbacks to outcomes #184

Closed
wants to merge 4 commits into from
Closed

Add callbacks to outcomes #184

wants to merge 4 commits into from

Conversation

tfausak
Copy link
Collaborator

@tfausak tfausak commented May 3, 2014

Fixes #139.

Interaction
  .run(inputs)
  .when_invalid do |outcome|
    # ...
  end
  .when_valid do |result|
    # ...
  end

@tfausak tfausak added this to the v1.3.0 milestone May 3, 2014
@tfausak tfausak self-assigned this May 3, 2014
@AaronLasseigne
Copy link
Owner

  1. What do we get by doing this?
  2. Why the when_ prefix?
  3. Is there a situation where you succeed but still want the outcome? You can always get to result form the outcome but not the other way around. Should they both be getting outcome?
  4. Should we force users to provide both cases if they go this route?

@tfausak
Copy link
Collaborator Author

tfausak commented May 6, 2014

  1. An alternative way to deal with interaction outcomes. It's arguably easier and more explicit.
  2. I thought it read better. I'm willing to remove it, though.
  3. The only situation I can think of off the top of my head is needing the valid inputs after running the interaction. But I didn't want to yield the outcome to the valid block because then the first line of every block would be result = outcome.result.
  4. That's interesting. I hadn't considered it. Is it really necessary since there are only two cases to consider? I guess it's not too much overhead to do .when_invalid { |_| }.

@tfausak
Copy link
Collaborator Author

tfausak commented May 8, 2014

After thinking about it some more, I'm confident that we shouldn't yield outcome to the valid block. That would be like returning outcome from run!, which we decided against in #26.

@tfausak
Copy link
Collaborator Author

tfausak commented May 8, 2014

I'm assuming you got the idea to require both cases from David Copeland's RubyConf talk. To make our code work like his code, I think we'd have to change it a little.

Interaction.run!(inputs) do |outcome|
  outcome.invalid do |errors|
    # Do something with outcome and errors.
  end.valid do |result|
    # Do something with outcome and result.
  end
end

If we didn't do something like this, there would be no way to know if all of the cases had been provided.

@tfausak tfausak closed this Aug 14, 2014
@tfausak tfausak deleted the outcome-callbacks branch August 14, 2014 19:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants