Replies: 1 comment
-
Happy New Year to you too! 🎉 Yes, you should always use lambdas for anything dynamic or else it is evaluated on code load, when the inputs are defined. I’m sorry you lost some time with this. This is a such a common gotcha that Rails scopes or FactoryBot definitions that accepted lambdas as well as regular values now only accept lambdas so that developers don’t get bitten by this. Perhaps we should do the same in this gem. Unfortunately that would mean requiring a longer syntax, even for simple inputs, such as: # would not be allowed
input :count, default: 0
# would be allowed
input :count, default: -> { 0 } Maybe a first step would be to only document the lambda syntax? Or raise/warn when using dates without lambdas? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi all + HNY. Very much enjoying Actor having previously implemented command pattern with Interactor.
I've just solved what's been a real head-scratcher for me. With an Actor I was setting an input's default value to
DateTime.now
and took be a bit of time to work out this seems to be evaluated/cached once unless a Proc is used.I considered creating an Issue for this, but after more thought realised it's probably a design decision but wanted to flag it here before submitting a PR with a README update.
This Actor...
...outputs this....
(You can see that the first input,
start_date
is not being updated between invocations)Looking back on it now it seems obvious the Proc is needed for the evaluation (the README references an array.sample example), but just wanted to check it's expected behaviour that the default value for
start_date
is in fact only meant to be evaluated/set once?!Beta Was this translation helpful? Give feedback.
All reactions