Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 | 669x 669x 669x 669x 669x 669x 669x 669x 669x 669x 669x 669x 669x 669x 669x 669x 669x 669x 669x 669x 669x 669x 669x 669x 669x 669x 669x 669x 669x 669x 669x 669x 669x 669x 669x 669x 669x 669x 2047x 2047x 2047x 669x 669x 669x 669x 669x 2047x 2047x 669x 669x 669x 669x 669x 669x 669x 669x 964x 964x 669x 669x 669x 669x 669x 669x 734318x 734318x 734318x 669x 669x 669x 669x 669x 669x 669x 6x 4x 4x 2x 2x 2x 2x 2x 6x 669x 669x 669x 669x 669x 669x 669x 669x 6661x 6661x 6649x 6649x 6661x 6661x 7244x 7244x 583x 583x 583x 6661x 6661x 669x 669x 669x 669x 669x 669x 669x 370220x 4787x 4787x 988x 988x 988x 4787x 4787x 1528x 1528x 1528x 4787x 4787x 4787x 4787x 8x 8x 8x 8x 4787x 370220x 669x 669x 669x 669x 669x 669x 669x 669x 669x 669x 669x 669x 669x 669x 669x 669x 669x 669x 669x 669x 12x 12x 12x 669x 669x 669x 669x 669x 669x 1x 1x 669x 669x 669x 669x 669x 1x 1x 669x 669x 669x 669x 669x 669x 669x 669x 669x 729430x 488505x 488505x 488505x 729430x 729430x 729430x 729430x 729430x 729430x 729430x 729430x 729455x 729454x 729454x 729455x 729430x 729430x 3x 3x 3x 3x 3x 3x 3x 3x 3x 729430x 729430x 729430x 1353x 1365x 1365x 1044x 1044x 1044x 1055x 2x 2x 2x 2x 1053x 1053x 950x 950x 950x 950x 950x 950x 950x 950x 950x 950x 950x 950x 950x 950x 950x 44x 44x 950x 950x 950x 1055x 1042x 1365x 1351x 729428x 729428x 729428x 729430x 240882x 240882x 240882x 729430x 729430x 729430x 488505x 488505x 729430x 729430x 669x 669x 669x 669x 669x 669x 15x 15x 9x 9x 15x 6x 6x 15x 2x 5x 5x 15x 4x 6x 6x 4x 15x 669x 669x 669x 669x 669x 669x 1121x 1121x 1121x 1121x 1121x 1121x 1121x 1121x 1121x 1121x 1121x 2x 2x 2x 1121x 1121x 1121x 1121x 1121x 1121x 1121x 1121x 1121x 1121x 1121x 1121x 1121x 1121x 1121x 1121x 1121x 1121x 1121x 1121x 1121x 1121x 1121x 1121x 1121x 1121x 1121x 1121x 1121x 1121x 1121x 1121x 1121x 1121x 83x 83x 83x 1121x 1121x 2x 2x 1121x 1121x 1121x 1121x 1121x 1121x 1x 1x 1121x 1121x 1121x 1121x 1121x 1x 1x 1121x 1121x 1121x 1121x 1121x 1121x 2038x 2038x 2038x 2038x 2038x 2038x 2038x 6x 2038x 2032x 2032x 2038x 4x 4x 2034x 2034x 2035x 4x 4x 2038x 2038x 2038x 2038x 1121x 1121x 1121x 1121x 1121x 1121x 1985x 1861x 1861x 1861x 1981x 1985x 1121x 1121x 1121x 1121x 1121x 1121x 1121x 1121x 4787x 4787x 4787x 4787x 4787x 2861x 2861x 4787x 1121x 1121x 1121x 1121x 1121x 1121x 2034x 1481x 302x 302x 1481x 2034x 1121x 1121x 1121x 1121x 1121x 1121x 1121x 910x 910x 910x 4x 2x 2x 4x 2x 2x 4x 4x 4x 1x 1x 1x 1x 1x 1x 1x 1x 4x 4x 4x 906x 910x 3x 3x 3x 3x 2x 2x 3x 3x 3x 1x 1x 1x 1x 1x 1x 1x 3x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 903x 903x 910x 1121x 1121x 1121x 1121x 1121x 950x 950x 949x 949x 949x 950x 37x 3x 2x 2x 3x 1x 1x 1x 1x 3x 3x 3x 34x 37x 34x 34x 950x 856x 856x 856x 856x 910x 56x 56x 56x 56x 56x 4x 4x 4x 4x 4x 4x 56x 52x 52x 52x 56x 56x 54x 54x 54x 54x 54x 56x 950x 949x 949x 950x 1121x 1121x 1121x 1121x 1121x 522x 1x 1x 1x 522x 522x 522x 522x 522x 666x 666x 522x 522x 1121x 669x 669x 669x 669x 669x 669x 669x 669x 2x 2x 2x 2x 2x 2x | /**
* @file watcher.js
* @description General-purpose state watcher and reactivity dependency tracking for Avenx-JS.
*/
import { tracer } from '../trace/tracer.js';
import { traceWatcher } from '../trace/reactive.js';
import { reportWatcherCycle } from './scheduler.js';
/**
* WeakMap tracking raw target to Map of keys to Set of active Watchers depending on them.
* @type {WeakMap<object, Map<string, Set<AvenxWatcher>>>}
*/
export const depMap = new WeakMap();
/**
* WeakMap tracking nested child targets to their parent relationship.
* @type {WeakMap<object, {parentTarget: object, parentKey: string}>}
*/
export const parentMap = new WeakMap();
/**
* The currently active watcher evaluating a reactive expression/function.
* @type {AvenxWatcher|null}
*/
export let activeWatcher = null;
/**
* Call stack of active watchers.
* @type {AvenxWatcher[]}
*/
const watcherStack = [];
/**
* Pushes a watcher onto the active evaluation context stack.
* @param {AvenxWatcher} watcher - The watcher instance to run.
*/
export function pushWatcher(watcher) {
watcherStack.push(activeWatcher);
activeWatcher = watcher;
}
/**
* Pops the active watcher context from the stack.
*/
export function popWatcher() {
activeWatcher = watcherStack.pop();
}
let debugReactivity = false;
/**
* Programmatically enables or disables debug reactivity logging.
* @param {boolean} enabled
*/
export function setDebugReactivity(enabled) {
debugReactivity = Boolean(enabled);
}
/**
* Returns whether debug reactivity logging is currently enabled.
* @returns {boolean}
*/
export function isDebugReactivityEnabled() {
if (typeof globalThis !== 'undefined' && typeof globalThis.__avenx_debug_reactivity__ === 'boolean') {
return globalThis.__avenx_debug_reactivity__;
}
return debugReactivity;
}
/**
* Formats a value for debug logging output.
* @param {any} val
* @returns {string}
*/
export function formatValue(val) {
if (typeof val === 'string') {
return `"${val}"`;
}
if (val === undefined) {
return 'undefined';
}
if (val === null) {
return 'null';
}
if (typeof val === 'symbol') {
return val.toString();
}
if (typeof val === 'object') {
try {
return JSON.stringify(val);
} catch {
return String(val);
}
}
return String(val);
}
/**
* Constructs the full property path from a target object and key using parentMap.
* @param {object} target
* @param {string|symbol} key
* @returns {string}
*/
export function getPropertyPath(target, key) {
const parts = [];
if (key !== undefined && key !== null) {
parts.unshift(String(key));
}
let current = target;
while (current) {
const relation = parentMap.get(current);
if (!relation) break;
parts.unshift(String(relation.parentKey));
current = relation.parentTarget;
}
return parts.join('.');
}
/**
* Tracks a property access on a target, establishing a dependency relationship.
* @param {object} target - The raw reactive target object.
* @param {string} key - The property key accessed.
*/
export function track(target, key) {
if (activeWatcher) {
let keysMap = depMap.get(target);
if (!keysMap) {
keysMap = new Map();
depMap.set(target, keysMap);
}
let watchers = keysMap.get(key);
if (!watchers) {
watchers = new Set();
keysMap.set(key, watchers);
}
watchers.add(activeWatcher);
activeWatcher.addDep(target, key, watchers);
if (isDebugReactivityEnabled()) {
const propPath = getPropertyPath(target, key);
const watcherName = activeWatcher.name || (activeWatcher.options && activeWatcher.options.name) || 'anonymous';
console.log(`[Avenx Debug] Tracked property "${propPath}" by Watcher "${watcherName}"`);
}
}
}
import { AvenxErrorCodes, formatMessage } from '../runtime/AvenxError.js';
import { logger } from '../runtime/AvenxLogger.js';
let triggerDepth = 0;
const MAX_TRIGGER_DEPTH = 50;
const triggeredWatchers = new Set();
const activeUpdatingWatchers = new Set();
const causationTrace = [];
/**
* Renders one causation entry.
*
* Entries are recorded as `{target, key}` rather than as a formatted path: the
* path walks the parent chain and joins strings, and it was built on *every*
* write for a diagnostic that fires only when a cycle is detected. A watcher
* name is already a string and is kept as one.
* @param {object|string} entry - A recorded entry.
* @returns {string} The property path or watcher label.
*/
function formatCausationEntry(entry) {
return typeof entry === 'string' ? entry : getPropertyPath(entry.target, entry.key);
}
/**
* Returns the current active causation trace for diagnostics.
* @returns {string[]}
*/
export function getActiveCausationTrace() {
return causationTrace.map(formatCausationEntry);
}
/**
* Clears the causation trace log.
*/
export function clearCausationTrace() {
causationTrace.length = 0;
}
/**
* Triggers all watchers registered to a mutated property, and propagates to parent nodes.
* @param {object} target - The raw target where mutation occurred.
* @param {string} key - The property key mutated.
* @param {any} [oldValue] - Previous value before mutation.
* @param {any} [newValue] - New value after mutation.
*/
export function trigger(target, key, oldValue, newValue) {
if (triggerDepth === 0) {
triggeredWatchers.clear();
causationTrace.length = 0;
}
triggerDepth++;
if (triggerDepth > MAX_TRIGGER_DEPTH) {
const cycleStr = causationTrace.slice(-6).map(formatCausationEntry).join(' -> ') || 'synchronous-watcher-cycle';
logger.error(
formatMessage(
AvenxErrorCodes.REACTIVE_DEADLOCK_DETECTED,
' (synchronous cascade loop)',
` ${cycleStr}\n\nSynchronous mutation cascade exceeded ${MAX_TRIGGER_DEPTH} levels. Aborted.`
)
);
triggerDepth--;
return;
}
try {
const keys = Array.isArray(key) ? key : [key];
for (const k of keys) {
if (typeof k !== 'symbol') {
causationTrace.push({ target, key: k });
}
}
if (isDebugReactivityEnabled()) {
for (const k of keys) {
if (typeof k !== 'symbol') {
const propPath = getPropertyPath(target, k);
const oldFormatted = formatValue(oldValue);
const newFormatted = formatValue(newValue);
console.log(`[Avenx Debug] Triggered property "${propPath}" (old: ${oldFormatted}, new: ${newFormatted}) -> scheduling update`);
}
}
}
const keysMap = depMap.get(target);
if (keysMap) {
for (const k of keys) {
const watchers = keysMap.get(k);
if (watchers) {
// Copy to prevent concurrent modification issues during execution
const toRun = new Set(watchers);
for (const watcher of toRun) {
if (activeUpdatingWatchers.has(watcher)) {
const cycleStr = `${watcher.name || 'anonymous'} -> ${causationTrace.map(formatCausationEntry).join(' -> ')} -> ${watcher.name || 'anonymous'}`;
reportWatcherCycle(watcher, cycleStr);
continue;
}
if (!triggeredWatchers.has(watcher)) {
triggeredWatchers.add(watcher);
if (watcher.name) {
causationTrace.push(`[${watcher.name}]`);
}
if (typeof watcher.update === 'function') {
// Recorded inside the write's causal scope, so the trace reads
// "this property changed, and that woke this watcher". The
// ephemeral causationTrace above is kept as-is: it exists to
// describe a deadlock at the moment one is detected, and is
// cleared as the cascade unwinds.
const token = tracer.on ? traceWatcher(watcher) : -1;
try {
watcher.update();
} finally {
if (token >= 0) {
tracer.leave(token);
}
}
}
}
}
}
}
}
// Propagate triggering to parents in case target is a nested object
const parentRelation = parentMap.get(target);
if (parentRelation) {
const { parentTarget, parentKey } = parentRelation;
trigger(parentTarget, parentKey, oldValue, newValue);
}
} finally {
triggerDepth--;
if (triggerDepth === 0) {
causationTrace.length = 0;
}
}
}
/**
* Recursively traverses a reactive value to register deep dependencies.
* @param {any} value
* @param {Set<any>} [seen]
*/
function traverse(value, seen = new Set()) {
if (value === null || typeof value !== 'object') {
return;
}
if (seen.has(value)) {
return;
}
seen.add(value);
if (Array.isArray(value)) {
for (let i = 0; i < value.length; i++) {
traverse(value[i], seen);
}
} else {
for (const key of Object.keys(value)) {
traverse(value[key], seen);
}
}
}
/**
* AvenxWatcher handles dependency tracking, caching, lazy/immediate callbacks,
* and lifecycle cleanup for reactive expressions.
*/
export class AvenxWatcher {
#isPaused = false;
/**
* @param {Function|Array<Function>} getter - The reactive evaluation function.
* @param {Function|null} [callback] - Callback triggered when evaluated value changes.
* @param {object} [options] - Configuration options.
* @param {boolean} [options.immediate] - Run the callback immediately with initial value.
* @param {boolean} [options.lazy] - Postpone the initial evaluation until first accessed.
*/
constructor(getter, callback = null, options = {}) {
if (typeof callback === 'object' && callback !== null) {
options = callback;
callback = null;
}
/** @type {boolean} */
this.isArray = Array.isArray(getter);
/** @type {Function|Array<Function>} */
this.getter = getter;
/** @type {Function|null} */
this.callback = typeof callback === 'function' ? callback : null;
/** @type {object} */
this.options = options || {};
/** Owning component, used to attribute synchronous cycles to a deadlock boundary. @type {any} */
this.component = this.options.component || null;
/** @type {boolean} */
this.isEffect = !this.callback || !!options.isEffect || !!options.effect;
/** @type {string} */
this.name = (options && (options.name || options.id)) || (Array.isArray(getter) ? 'multi-watcher' : (getter && getter.name)) || 'anonymous';
/** @type {Set<{target: object, key: string, watchersSet: Set<AvenxWatcher>}>} */
this.deps = new Map();
/** @type {boolean} */
this.dirty = true;
/** @type {any} */
this.value = undefined;
/** @type {any} */
this.debounceTimer = null;
/** @type {any} */
this.throttleTimer = null;
/** @type {number} */
this.lastExecTime = 0;
/** @type {any} */
this.pendingNewValue = undefined;
/** @type {any} */
this.pendingOldValue = undefined;
if (!options.lazy) {
this.value = this.get();
this.dirty = false;
}
if (options.immediate && this.callback) {
this.callback(this.value, undefined);
}
}
/**
* Pauses watcher execution.
*/
pause() {
this.#isPaused = true;
}
/**
* Resumes watcher execution.
*/
resume() {
this.#isPaused = false;
}
/**
* Evaluates the getter function inside the watcher context to track reactive dependencies.
* @returns {any}
*/
get() {
pushWatcher(this);
const oldDeps = this.deps;
this.deps = new Map();
try {
let value;
if (this.isArray) {
value = this.getter.map((fn) => fn());
} else {
value = this.getter();
}
if (this.options.deep) {
traverse(value);
}
this.cleanupDeps(oldDeps);
return value;
} catch (err) {
this.deps = oldDeps;
throw err;
} finally {
popWatcher();
}
}
/**
* Evaluates a lazy computed watcher if it is dirty.
* @returns {any}
*/
evaluate() {
if (this.dirty) {
this.value = this.get();
this.dirty = false;
}
return this.value;
}
/**
* Registers a target property dependency on this watcher.
* @param {object} target - Reactive object target.
* @param {string} key - Property key.
* @param {Set<AvenxWatcher>} watchersSet - Set mapping to this dependency.
*/
addDep(target, key, watchersSet) {
// Keyed by the watcher set rather than scanned for it. A render effect
// reads every value it displays, so a component with a few hundred
// bindings made this a linear scan per read -- quadratic in the number of
// reads, on the hot path of every evaluation.
if (!this.deps.has(watchersSet)) {
this.deps.set(watchersSet, { target, key, watchersSet });
}
}
/**
* Compares active dependencies against old dependencies and unsubscribes from stale dependencies.
* @param {Set<{target: object, key: string, watchersSet: Set<AvenxWatcher>}>} oldDeps
*/
cleanupDeps(oldDeps) {
for (const [watchersSet] of oldDeps) {
if (!this.deps.has(watchersSet)) {
watchersSet.delete(this);
}
}
}
/**
* Executes the watcher callback, applying debounce or throttle timing if configured.
* @param {any} newValue
* @param {any} oldValue
*/
run(newValue, oldValue) {
if (!this.callback) return;
if (typeof this.options.debounce === 'number' && this.options.debounce > 0) {
if (this.debounceTimer) {
clearTimeout(this.debounceTimer);
}
if (this.pendingOldValue === undefined) {
this.pendingOldValue = oldValue;
}
this.pendingNewValue = newValue;
this.debounceTimer = setTimeout(() => {
const toNew = this.pendingNewValue;
const toOld = this.pendingOldValue;
this.pendingNewValue = undefined;
this.pendingOldValue = undefined;
this.debounceTimer = null;
if (this.callback) {
this.callback(toNew, toOld);
}
}, this.options.debounce);
return;
}
if (typeof this.options.throttle === 'number' && this.options.throttle > 0) {
const now = Date.now();
const remaining = this.options.throttle - (now - (this.lastExecTime || 0));
if (this.pendingOldValue === undefined) {
this.pendingOldValue = oldValue;
}
this.pendingNewValue = newValue;
if (remaining <= 0 || remaining > this.options.throttle) {
if (this.throttleTimer) {
clearTimeout(this.throttleTimer);
this.throttleTimer = null;
}
this.lastExecTime = now;
const toNew = this.pendingNewValue;
const toOld = this.pendingOldValue;
this.pendingNewValue = undefined;
this.pendingOldValue = undefined;
this.callback(toNew, toOld);
} else if (!this.throttleTimer) {
this.throttleTimer = setTimeout(() => {
this.lastExecTime = Date.now();
this.throttleTimer = null;
const toNew = this.pendingNewValue;
const toOld = this.pendingOldValue;
this.pendingNewValue = undefined;
this.pendingOldValue = undefined;
if (this.callback) {
this.callback(toNew, toOld);
}
}, remaining);
}
return;
}
this.callback(newValue, oldValue);
}
/**
* Updates the watcher value and triggers evaluation or callback execution.
*/
update() {
if (this.#isPaused) return;
if (activeUpdatingWatchers.has(this)) {
const cycleStr = `${this.name} -> ${causationTrace.map(formatCausationEntry).join(' -> ')} -> ${this.name}`;
reportWatcherCycle(this, cycleStr);
return;
}
activeUpdatingWatchers.add(this);
try {
if (this.isEffect) {
if (typeof this.options.debounce === 'number' && this.options.debounce > 0) {
if (this.debounceTimer) {
clearTimeout(this.debounceTimer);
}
this.debounceTimer = setTimeout(() => {
this.debounceTimer = null;
if (!this.#isPaused) {
this.value = this.get();
}
}, this.options.debounce);
return;
}
if (typeof this.options.throttle === 'number' && this.options.throttle > 0) {
const now = Date.now();
const remaining = this.options.throttle - (now - (this.lastExecTime || 0));
if (remaining <= 0 || remaining > this.options.throttle) {
if (this.throttleTimer) {
clearTimeout(this.throttleTimer);
this.throttleTimer = null;
}
this.lastExecTime = now;
this.value = this.get();
} else if (!this.throttleTimer) {
this.throttleTimer = setTimeout(() => {
this.lastExecTime = Date.now();
this.throttleTimer = null;
if (!this.#isPaused) {
this.value = this.get();
}
}, remaining);
}
return;
}
this.value = this.get();
} else if (this.options.lazy) {
this.dirty = true;
if (this.callback) {
this.run(this.value, this.value);
}
} else {
const oldValue = this.value;
const newValue = this.get();
let hasChanged;
if (this.isArray) {
if (!Array.isArray(oldValue) || newValue.length !== oldValue.length) {
hasChanged = true;
} else {
hasChanged = newValue.some(
(val, i) => val !== oldValue[i] || (val && typeof val === 'object'),
);
}
} else {
hasChanged =
newValue !== oldValue || (newValue && typeof newValue === 'object');
}
if (hasChanged) {
this.value = newValue;
if (this.callback) {
this.run(newValue, oldValue);
}
}
}
} finally {
activeUpdatingWatchers.delete(this);
}
}
/**
* Cleans up all registered dependencies of this watcher to prevent memory leaks.
*/
teardown() {
if (this.debounceTimer) {
clearTimeout(this.debounceTimer);
this.debounceTimer = null;
}
if (this.throttleTimer) {
clearTimeout(this.throttleTimer);
this.throttleTimer = null;
}
this.pendingNewValue = undefined;
this.pendingOldValue = undefined;
for (const [watchersSet] of this.deps) {
watchersSet.delete(this);
}
this.deps.clear();
}
}
/**
* Creates an immediate effect watcher that automatically tracks reactive state properties accessed during execution and re-runs on mutation.
* @param {Function} effect - The side-effect function to execute and track.
* @param {object} [options] - Configuration options (e.g. debounce, throttle, deep, name).
* @returns {Function} Stop handle function () => watcher.teardown().
*/
export function watchEffect(effect, options = {}) {
if (typeof effect !== 'function') {
throw new Error('watchEffect requires an effect function');
}
const watcher = new AvenxWatcher(effect, null, options);
const stop = () => watcher.teardown();
stop.watcher = watcher;
return stop;
}
|