UNPKG

entangle.ts

Version:

A declarative, event-driven framework for orchestrating business logic in TypeScript & Node.js applications.

48 lines (47 loc) 1.96 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.QuantumPointer = void 0; /** * Represents a lazy, deferred reference to a particle within a specific scope. * * In our physics analogy, a QuantumPointer doesn't hold the particle itself, * but rather "points" to a location in a "bubble universe" (a scope) * where a particle is expected to exist. The actual particle is only resolved * or "collapsed" from its potential state when the `.get()` method is called. * * This solves the problem of needing to reference a particle that might not have * been instantiated at the moment a rule is defined. * * @template T The expected type of the particle instance. */ class QuantumPointer { /** * The constructor is private to enforce the use of the static `create` method, * leading to a cleaner and more declarative API. * @param particleClass The class of the particle to be retrieved. * @param scope The specific scope (HiggsField instance) to search within. */ constructor(particleClass, scope) { this.particleClass = particleClass; this.scope = scope; } /** * Creates a new instance of a QuantumPointer. * @template T The expected type of the particle instance. * @param particleClass The class of the particle to be retrieved. * @param scope The specific scope (HiggsField instance) where the particle is expected to be. * @returns A new `QuantumPointer` instance. */ static create(particleClass, scope) { return new QuantumPointer(particleClass, scope); } /** * Resolves the pointer and retrieves the actual particle instance from the scope. * This is the "observation" that collapses the potential state into a concrete instance. * @returns The resolved particle instance. */ get() { return this.scope.get(this.particleClass); } } exports.QuantumPointer = QuantumPointer;