Closed orenelbaum closed 3 years ago
Okay so after some discussions, this is what the design is in my mind right now (and also some of their pros/cons).
$:
labelOutputs createMemo
for VariableDeclaration
(var
kind) while createEffect(() => expr)
for $: expr
. It will serve as a middle point for memo:
and effect:
as there are expressions that do not work for $:
that is intepreted differently by memo:
and effect
: (for instance, AssignmentExpression
).
$
CTF and $effect
This should be easy to implement in theory, although $effect
would be the tricky part. Since $effect
cannot support block statements, it would just behave like createEffect
with an auto-import, at the least.
Implemented $:
and $
CTF for the upcoming release. $effect
would be on-hold for further design discussions.
Moving $effect
discussion to #2
Features description:
$effect
CTFThe
$effect
CTF is pretty straight forward:$effect(console.log("hi" + y))
$
label and CTFThe
$
label and CTF are a more concise way to write memos and effects.$
labelThe
$
label would act like amemo
label if the labeled statement is a variable declaration, otherwise it would act like aneffect
label.$: console.log(x() + 1)
=>effect: console.log(x() + 1)
$: var x = y() + 1
=>memo: var x = y() + 1
$: x = y() + 1
=>effect: x = y() + 1
This could be less confusing if support is dropped formemo
labels with assignments instead of variable declaration (memo: x = y() + 1
instead ofmemo: var x = y() + 1
.$
CTFThe
$
CTF would act like a$memo
CTF if the CTF call expression initializes aconst
declaration, otherwise it would act like an$effect
CTF.$(console.log(x() + 1))
=>$effect(console.log(x() + 1))
const x = $(y() + 1)
=>const x = $(y() + 1)
x = $(y() + 1)
=> Error orx = $effect(y() + 1)
if that's not an error. I'm not sure exactly how the$memo
CTF works but again this could be less confusing if the$memo
CTF is required to initialize aconst
declaration