mutations icon indicating copy to clipboard operation
mutations copied to clipboard

alternative approach to avoid instance variable and success? condition

Open andriytyurnikov opened this issue 8 years ago • 1 comments

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?

andriytyurnikov avatar May 14 '16 02:05 andriytyurnikov

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

eliank avatar Jun 21 '16 09:06 eliank