-
Notifications
You must be signed in to change notification settings - Fork 0
Comparison
૮༼⚆︿⚆༽つ edited this page Sep 23, 2023
·
11 revisions
Comparison between Nusa micro-syntax vs various JS framework for reactive programming. (some details like variables and functions declaration are omitted)
Change input.value
to foo
when it's changed.
<input ~ .value="foo">
Change input.value
to foo
or bar
if one of them are changed.
<input ~ .value="foo bar">
<input ~ .value="foo~>bar">
<!-- or -->
<input ~ .value="bar<~foo">
effect(() => { bar.value = foo.value });
<input value={bar}/>
<input ~ .value="(foo,bar)~>ret:concat">
<!-- or -->
<input ~ .value="ret:concat<~(foo,bar)">
const result = computed(
() => concat(foo.value, bar.value)
);
<input value={result}/>
const result = () => concat(foo(), bar());
<input value={result()}/> // dunno if it can be inlined 🤔
<script>
$: value = concat(foo. bar)
</script>
<input {value}>
<input ~ .value="(foo,bar)<~>ret:concat" @change=call>
<!-- or -->
<input ~ .value="ret:concat<~>(foo,bar)" @change=call>
function listen(event) {
const ret = concat(event.target.value)
untrack(() => {
foo.value = bar.value = ret
})
event.target.value = ret
};
const result = computed(() =>
concat(foo.value, bar.value)
);
<input value={result} onchange={listen}/>
<input ~ .value="(foo,bar)~>call:print">
<!-- or -->
<input ~ .value="call:print<~(foo,bar)">
const input = document.querySelector("input")
effect(current => {
print(foo.value, bar.value)
input.value = current // value can be either foo or bar, depend on which signal are changed
})