lxsmnsyc / solid-labels

Simple, reactive labels for SolidJS
MIT License
243 stars 8 forks source link

Feature request | "$effect" CTF and "$" label and CTF #1

Closed orenelbaum closed 3 years ago

orenelbaum commented 3 years ago

Features description:

$effect CTF

The $effect CTF is pretty straight forward: $effect(console.log("hi" + y))

$ label and CTF

The $ label and CTF are a more concise way to write memos and effects.

$ label

The $ label would act like a memo label if the labeled statement is a variable declaration, otherwise it would act like an effect 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 for memo labels with assignments instead of variable declaration (memo: x = y() + 1 instead of memo: var x = y() + 1.

$ CTF

The $ CTF would act like a $memo CTF if the CTF call expression initializes a const 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 or x = $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 a const declaration

lxsmnsyc commented 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).

$: label

Outputs 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.

lxsmnsyc commented 3 years ago

Implemented $: and $ CTF for the upcoming release. $effect would be on-hold for further design discussions.

lxsmnsyc commented 3 years ago

Moving $effect discussion to #2