Open justinfagnani opened 7 months ago
Option 1 is my preference as well with decorators, prevents usneeded function execution in the simple (usually more common) case.
@cached could accept options as well
Sounds like a good idea!
Oops... I meant to say that I prefer option (2)! I found that a lot of decorators take options, so always having the ()
after the decorator provides visual consistency. It also makes it easier to add options in the future even if a decorator doesn't take them now.
There is no reason both can't be supported simultaneously, as it turns out. Invocation without options is just {} for options.
But i do think this should be avoided for faster module evaluation
@signal
is a wrapper fornew Signal.State()
but it does not expose the options argument.It should be possible to do:
There would be two options for the
signal()
signature:@signal accessor foo
for non-options usage and@signal({...}) accessor foo
for options usage.@signal() accessor foo
for non-options usage and@signal({...}) accessor foo
for options usage.(2) is possible by duck-typing the arguments.
I personally prefer style (2) for consistency, but there's also consistency to consider with the other decorators. I guess
@cached
could accept options as well, since it's basically a wrapper fornew Signal.Computed()
.