silmaril

Composition

$composable

$composable(setup) wraps a function so that it can use reactive variables, $, $sync, $store, onMount and onDestroy. Call it from a $$, another $composable, or the body of a $ or $sync.

composition-squared.js

No logs.

The composable runs in its own scope under the scope of its caller.

Called through a namespace import (import * as s from 'silmaril'), $$ and $composable still run, but without reactivity.

Order across scopes

A value that moves from one scope to another through a store is a new write in the second scope. The scopes run in a fixed order. A body that reads values from both sides can see a new value next to an old one, then run again.

$ and $sync as scopes

The body of $ and $sync is a scope. Variables declared in it are reactive, and onMount, onDestroy and $store work there.

Each run disposes the scope of the last run and makes a new one. Variables declared in the body start again, and onDestroy callbacks of the last run fire first.

composition-nested.js

No logs.

The outer $ reads y, so a change to y runs it again, and it destroys the inner scope first. The inner $ tracks its own reads. A read inside it does not make the outer body run again.

Rules for nested entries: