make(gc?)
Create an isolated Tilia context with its own reactive world.
function make(gc?: number): Tilialet make: (~gc: int=?, unit) => tiliamake creates a context object containing the Tilia API (tilia, carve, observe, watch, batch, signal, derived, source, store, _observe).
Each context is isolated: observers and proxies from one context do not share tracking with another context. Use this to create independent reactive worlds.
gc sets the garbage-collection threshold for cleared watchers. The default is 50. See tilia, Tilia, and the guide chapter Mistakes stay small.
import { make } from "tilia";
// One context is right for almost every application, and the top-level
// functions use it. A library that must not share tracking with its host —
// a plugin rendered inside someone else's tilia app — builds its own.
const plugin = make();
const { tilia, observe } = plugin;
const state = tilia({ visible: false });
observe(() => {
panel.hidden = !state.visible;
});
// The other reason to call it: the garbage-collection threshold. A host that
// mounts and unmounts thousands of observers a minute may sweep less often.
const app = make(500);open Tilia
// One context is right for almost every application, and the top-level
// functions use it. A library that must not share tracking with its host —
// a plugin rendered inside someone else's tilia app — builds its own.
let plugin = make()
let state = plugin.tilia({visible: false})
plugin.observe(() => panel.hidden = !state.visible)->ignore
// The other reason to call it: the garbage-collection threshold. A host that
// mounts and unmounts thousands of observers a minute may sweep less often.
let app = make(~gc=500)