context
/** * @param id - Optional ID for new context. If not provided, a unique ID will be generated. * @returns A new Context object with initialized reactive state management and DOM utilities. */context(id?:string): Context
The context system provides isolated environments for managing application state and performing operations. Each context includes its own reactive state management, DOM utilities, event handling, rendering functions, and a cleanup mechanism to release associated resources.
Basic Usage
Section titled “Basic Usage”import { context } from '@hellajs/core';
// Operations in one context don't affect the otherconst ctx1 = context('first');const ctx2 = context('second');// ...// Clean up when no longer neededctx1.cleanup();ctx2.cleanup();
Isolated Context Example
Section titled “Isolated Context Example”// Create a contextconst ctx = context('feature');
// Use context-specific reactivityconst count = ctx.signal(0);const doubled = ctx.computed(() => count() * 2);
// Create an effect within this contextctx.effect(() => { console.log(`Count is now: ${count()}, doubled: ${doubled()}`);});
// Updates are isolated to this contextcount.set(5);
// Cleanup when donectx.cleanup();