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

alternative approach to avoid instance variable and success? condition #102

Open
andriytyurnikov opened this issue May 14, 2016 · 1 comment

Comments

@andriytyurnikov
Copy link

Hi guys. Impressive work with mutations
Typical usecase for Command is

outcome = UserSignup.run(params)
if outcome.success?
  user = outcome.result
else
  render outcome.errors
end

...and what we may notice, is the only reason for having boolean attribute success? is to write if for it,
and the only reason to have outcome variable is to call success? on it

UserSignup
  .run(params)
  .on_success { |outcome| @user = outcome.user }
  .on_failure { |outcome| render outcome.errors }

And by using call method syntactical sugar we may get even sexier stuff

UserSignup.(params)
  .on_success { |outcome| @user = outcome.user }
  .on_failure { |outcome| render outcome.errors }

This success procs thing may be in parallel with usual success?
What do you think?

@eliank
Copy link
Collaborator

eliank commented Jun 21, 2016

I like the way it currently works, to me its more obvious and less magical

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