Reactive context
Context<T> holds a single value. It requires an initial value, exposes
getValue() and setValue(value), and notifies subscribers when set.
It is not AsyncLocalStorage, a DI scope, or an authentication mechanism.
import assert from 'node:assert/strict';
import { createContext } from '@tagna/udiot';
const locale = createContext('en');
let observed = '';
const unsubscribe = locale.subscribe(value => { observed = value; });
locale.setValue('kn');
assert.equal(locale.getValue(), 'kn');
assert.equal(observed, 'kn');
unsubscribe();
Use it for application-owned reactive preferences or state with an appropriate lifetime. Do not store authenticated users, tenant identity or request secrets in a module-level context on a multi-request server: concurrent requests would share the value, even if a finally block resets it afterward.
For server request data use createRequestScopeMiddleware and
getRequestContainer from @tagna/udiot/server; for tenant services see
multi-tenancy. Client-side user state is a presentation
convenience only; the server must enforce authentication and authorization.