mutations
mutations copied to clipboard
alternative approach to avoid instance variable and success? condition
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?
I like the way it currently works, to me its more obvious and less magical