Make foo.$
an alias for foo()
in the returned Accessor
s for createSignal()
and createMemo()
#2537
samualtnorman
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
As in for the accessors returned by
createSignal()
andcreateMemo()
,Object.defineProperty()
a getter that simply calls the function.For example you could have a "dollar-ize" function:
That you simply wrap around accessors:
This will be a read-only getter, no setter to maintain read/write segregation.
This fixes type narrowing in TypeScript where you are otherwise forced to use the error-prone postfix bang (
!
) operator:Maybe this could be expanded to other accessors from other functions in the future, but for now I think putting it on just
createSignal()
andcreateMemo()
is a minimal change that has a big impact.There is already precedent for getter-based reactivity in the form of
props.foo
andresource.latest
.I've seen a similar discussion but this looks like it requires compilation and to make the
Accessor
a little magical. That's not what I'm asking for, my suggestion doesn't touch compilation.Beta Was this translation helpful? Give feedback.
All reactions