yarn: yarn add ulive
npm: npm i ulive
cdn: https://esm.sh/ulive
module: https://esm.sh/ulive?module
- Small.
- Fast.
- Simple API
- Reactive.
- Circular Detection
This is function based signal.
yarn: yarn add ulive
npm: npm i ulive
module: https://esm.sh/ulive/fn?module
import { o, effect, memo, batch, untracked } from "ulive/fn";
const num = o(0);
num(10);
console.log(num());
Create a reactive or live state.
import { signal, computed, effect } from "ulive";
const num = signal(0);
num.value = 10;
console.log(num.value);
Run fn with automatic dependency check & cleanup return.
let num = signal(0);
effect(() => console.log(num.value));
Returns computed value.
let num = signal(0);
let square = computed(() => num.value * num.value);
let cube = computed(() => square.value * num.value);
effect(() => console.log(num.value, square.value, cube.value));
Defer effects.
let a = signal(0), b = signal(1)
let mul = computed(() => a.value * b.value);
effect(() => console.log(a.value, b.value, mul.value));
batch(() => (a++, b++));
Run without effects.
let a = signal(0), b = signal(1)
let mul = computed(() => a.value * b.value);
effect(() => untracked(() => console.log(a.value)));
const counter = signal(0);
const effectCount = signal(0);
effect(() => {
console.log(counter.value);
// Whenever this effect is triggered, increase `effectCount`.
// But we don't want this signal to react to `effectCount`
effectCount.value = effectCount.valueOf() + 1;
});
const num = signal(1);
let square = computed(() => num.value * num.value);
let cube = computed(() => square.value * num.value);
effect(() => console.log(num.value, square.value, cube.value));
num.value = 1;
num.value = 2;
num.value = 3;
MIT