@fluixi/reactive 1.0.0-alpha.92 → 1.0.0-alpha.94

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/dist/cdn/reactive.cjs +105 -35
  2. package/dist/cdn/reactive.global.js +2 -2
  3. package/dist/cdn/reactive.mjs +105 -35
  4. package/dist/cdn/signal.cjs +1 -1
  5. package/dist/cdn/signal.global.js +2 -2
  6. package/dist/cdn/signal.mjs +1 -1
  7. package/dist/index.cjs +105 -35
  8. package/dist/index.mjs +105 -35
  9. package/dist/lib/index.cjs +106 -36
  10. package/dist/lib/index.mjs +106 -36
  11. package/dist/lib/observable/index.cjs +1 -1
  12. package/dist/lib/observable/index.mjs +1 -1
  13. package/dist/lib/signal/api.cjs +11 -10
  14. package/dist/lib/signal/api.d.ts +5 -1
  15. package/dist/lib/signal/api.d.ts.map +1 -1
  16. package/dist/lib/signal/api.js +4 -2
  17. package/dist/lib/signal/api.mjs +11 -10
  18. package/dist/lib/signal/cached-resource.cjs +77 -34
  19. package/dist/lib/signal/cached-resource.d.ts +48 -68
  20. package/dist/lib/signal/cached-resource.d.ts.map +1 -1
  21. package/dist/lib/signal/cached-resource.js +59 -72
  22. package/dist/lib/signal/cached-resource.mjs +77 -34
  23. package/dist/lib/signal/graph/children.cjs +3 -2
  24. package/dist/lib/signal/graph/children.mjs +3 -2
  25. package/dist/lib/signal/graph/compat.cjs +10 -9
  26. package/dist/lib/signal/graph/compat.d.ts +3 -1
  27. package/dist/lib/signal/graph/compat.d.ts.map +1 -1
  28. package/dist/lib/signal/graph/compat.js +2 -2
  29. package/dist/lib/signal/graph/compat.mjs +10 -9
  30. package/dist/lib/signal/graph/core.cjs +2 -2
  31. package/dist/lib/signal/graph/core.mjs +2 -2
  32. package/dist/lib/signal/graph/debounced.cjs +9 -8
  33. package/dist/lib/signal/graph/debounced.mjs +9 -8
  34. package/dist/lib/signal/graph/derived.cjs +9 -8
  35. package/dist/lib/signal/graph/derived.mjs +9 -8
  36. package/dist/lib/signal/graph/error-boundary.cjs +3 -2
  37. package/dist/lib/signal/graph/error-boundary.mjs +3 -2
  38. package/dist/lib/signal/graph/index.cjs +2 -2
  39. package/dist/lib/signal/graph/index.mjs +2 -2
  40. package/dist/lib/signal/graph/observe.cjs +38 -3
  41. package/dist/lib/signal/graph/observe.d.ts +44 -0
  42. package/dist/lib/signal/graph/observe.d.ts.map +1 -1
  43. package/dist/lib/signal/graph/observe.js +50 -1
  44. package/dist/lib/signal/graph/observe.mjs +38 -3
  45. package/dist/lib/signal/graph/resource.cjs +9 -8
  46. package/dist/lib/signal/graph/resource.mjs +9 -8
  47. package/dist/lib/signal/graph/runtime.cjs +7 -6
  48. package/dist/lib/signal/graph/runtime.d.ts +1 -1
  49. package/dist/lib/signal/graph/runtime.d.ts.map +1 -1
  50. package/dist/lib/signal/graph/runtime.js +4 -4
  51. package/dist/lib/signal/graph/runtime.mjs +7 -6
  52. package/dist/lib/signal/graph/signal-next.cjs +39 -9
  53. package/dist/lib/signal/graph/signal-next.d.ts +1 -1
  54. package/dist/lib/signal/graph/signal-next.d.ts.map +1 -1
  55. package/dist/lib/signal/graph/signal-next.js +1 -1
  56. package/dist/lib/signal/graph/signal-next.mjs +39 -9
  57. package/dist/lib/signal/graph/ssr-hooks.cjs +29 -0
  58. package/dist/lib/signal/graph/ssr-hooks.d.ts +24 -0
  59. package/dist/lib/signal/graph/ssr-hooks.d.ts.map +1 -1
  60. package/dist/lib/signal/graph/ssr-hooks.js +36 -0
  61. package/dist/lib/signal/graph/ssr-hooks.mjs +29 -0
  62. package/dist/lib/signal/graph/state.cjs +1 -1
  63. package/dist/lib/signal/graph/state.mjs +1 -1
  64. package/dist/lib/signal/graph/suspense.cjs +3 -2
  65. package/dist/lib/signal/graph/suspense.mjs +3 -2
  66. package/dist/lib/signal/index-legacy.cjs +65 -34
  67. package/dist/lib/signal/index-legacy.mjs +65 -34
  68. package/dist/lib/signal/index.cjs +76 -12
  69. package/dist/lib/signal/index.d.ts +2 -1
  70. package/dist/lib/signal/index.d.ts.map +1 -1
  71. package/dist/lib/signal/index.js +1 -1
  72. package/dist/lib/signal/index.mjs +76 -12
  73. package/dist/lib/signal/list.cjs +3 -2
  74. package/dist/lib/signal/list.mjs +3 -2
  75. package/dist/lib/signal/resource-api.cjs +9 -8
  76. package/dist/lib/signal/resource-api.mjs +9 -8
  77. package/dist/lib/signal/signal.cjs +9 -8
  78. package/dist/lib/signal/signal.mjs +9 -8
  79. package/dist/lib/signal/utilities.cjs +10 -9
  80. package/dist/lib/signal/utilities.mjs +10 -9
  81. package/dist/lib/store/api.cjs +3 -2
  82. package/dist/lib/store/api.mjs +3 -2
  83. package/dist/lib/store/index.cjs +4 -3
  84. package/dist/lib/store/index.mjs +4 -3
  85. package/dist/lib/store/store.cjs +3 -2
  86. package/dist/lib/store/store.mjs +3 -2
  87. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  88. package/dist/version.generated.cjs +2 -2
  89. package/dist/version.generated.d.ts +1 -1
  90. package/dist/version.generated.js +1 -1
  91. package/dist/version.generated.mjs +2 -2
  92. package/package.json +2 -2
@@ -1,7 +1,7 @@
1
- /*! @fluixi/reactive v1.0.0-alpha.92 | (c) 2026 Ibrahima Touré and Fluixi contributors | MIT */
1
+ /*! @fluixi/reactive v1.0.0-alpha.94 | (c) 2026 Ibrahima Touré and Fluixi contributors | MIT */
2
2
 
3
3
  // src/version.generated.ts
4
- var VERSION = "1.0.0-alpha.92";
4
+ var VERSION = "1.0.0-alpha.94";
5
5
 
6
6
  // src/lib/signal/graph/state.ts
7
7
  var MAJOR = VERSION.split(".")[0];
@@ -51,11 +51,12 @@ function observeReactiveNodes(next) {
51
51
  }
52
52
  var running = [];
53
53
  var origin;
54
+ var currentScope;
54
55
  function reportReactiveNode(report) {
55
56
  const observer = G.observer;
56
57
  if (observer) {
57
58
  observer.created(
58
- report.parents === void 0 ? { ...report, parents: running, origin: report.origin ?? origin } : report
59
+ report.parents === void 0 ? { ...report, parents: running, origin: report.origin ?? origin, scope: report.scope ?? currentScope } : { ...report, scope: report.scope ?? currentScope }
59
60
  );
60
61
  }
61
62
  }
@@ -375,7 +376,7 @@ function batch(fn) {
375
376
  }
376
377
  }
377
378
  var EffectNode = class {
378
- constructor(fn, report = false) {
379
+ constructor(fn, report = false, name) {
379
380
  this.queued = false;
380
381
  this.disposed = false;
381
382
  this.owner = makeOwner(G.owner);
@@ -387,7 +388,7 @@ var EffectNode = class {
387
388
  if (typeof r === "function") (this.owner.cleanups ??= []).push(r);
388
389
  });
389
390
  });
390
- reportReactiveNode({ kind: "effect", node: this.computed, handle: this, internal: !report });
391
+ reportReactiveNode({ kind: "effect", node: this.computed, handle: this, internal: !report, ...name ? { name } : {} });
391
392
  this.watcher = new Watcher(() => enqueue(this));
392
393
  this.run();
393
394
  this.watcher.watch(this.computed);
@@ -414,8 +415,8 @@ var EffectNode = class {
414
415
  disposeOwner(this.owner);
415
416
  }
416
417
  };
417
- function effect(fn, report = false) {
418
- const node = new EffectNode(fn, report);
418
+ function effect(fn, report = false, name) {
419
+ const node = new EffectNode(fn, report, name);
419
420
  return () => node.dispose();
420
421
  }
421
422
 
@@ -483,12 +484,12 @@ function createMemo(fn, value, options) {
483
484
  if (isObserved()) onCleanup(() => reportReactiveDispose(c));
484
485
  return read;
485
486
  }
486
- function createEffect(fn, value) {
487
+ function createEffect(fn, value, options) {
487
488
  let prev = value;
488
489
  return effect(() => {
489
490
  const r = fn(prev);
490
491
  prev = r;
491
- }, true);
492
+ }, true, options?.name);
492
493
  }
493
494
  function createComputed(fn, value) {
494
495
  let prev = value;
@@ -1,4 +1,4 @@
1
- /*! @fluixi/reactive v1.0.0-alpha.92 | (c) 2026 Ibrahima Touré and Fluixi contributors | MIT */
1
+ /*! @fluixi/reactive v1.0.0-alpha.94 | (c) 2026 Ibrahima Touré and Fluixi contributors | MIT */
2
2
  "use strict";
3
3
  var __defProp = Object.defineProperty;
4
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -31,7 +31,7 @@ __export(core_exports, {
31
31
  module.exports = __toCommonJS(core_exports);
32
32
 
33
33
  // src/version.generated.ts
34
- var VERSION = "1.0.0-alpha.92";
34
+ var VERSION = "1.0.0-alpha.94";
35
35
 
36
36
  // src/lib/signal/graph/state.ts
37
37
  var MAJOR = VERSION.split(".")[0];
@@ -1,7 +1,7 @@
1
- /*! @fluixi/reactive v1.0.0-alpha.92 | (c) 2026 Ibrahima Touré and Fluixi contributors | MIT */
1
+ /*! @fluixi/reactive v1.0.0-alpha.94 | (c) 2026 Ibrahima Touré and Fluixi contributors | MIT */
2
2
 
3
3
  // src/version.generated.ts
4
- var VERSION = "1.0.0-alpha.92";
4
+ var VERSION = "1.0.0-alpha.94";
5
5
 
6
6
  // src/lib/signal/graph/state.ts
7
7
  var MAJOR = VERSION.split(".")[0];
@@ -26,7 +26,7 @@ __export(debounced_exports, {
26
26
  module.exports = __toCommonJS(debounced_exports);
27
27
 
28
28
  // src/version.generated.ts
29
- var VERSION = "1.0.0-alpha.92";
29
+ var VERSION = "1.0.0-alpha.94";
30
30
 
31
31
  // src/lib/signal/graph/state.ts
32
32
  var MAJOR = VERSION.split(".")[0];
@@ -76,11 +76,12 @@ function observeReactiveNodes(next) {
76
76
  }
77
77
  var running = [];
78
78
  var origin;
79
+ var currentScope;
79
80
  function reportReactiveNode(report) {
80
81
  const observer = G.observer;
81
82
  if (observer) {
82
83
  observer.created(
83
- report.parents === void 0 ? { ...report, parents: running, origin: report.origin ?? origin } : report
84
+ report.parents === void 0 ? { ...report, parents: running, origin: report.origin ?? origin, scope: report.scope ?? currentScope } : { ...report, scope: report.scope ?? currentScope }
84
85
  );
85
86
  }
86
87
  }
@@ -374,7 +375,7 @@ function batch(fn) {
374
375
  }
375
376
  }
376
377
  var EffectNode = class {
377
- constructor(fn, report = false) {
378
+ constructor(fn, report = false, name) {
378
379
  this.queued = false;
379
380
  this.disposed = false;
380
381
  this.owner = makeOwner(G.owner);
@@ -386,7 +387,7 @@ var EffectNode = class {
386
387
  if (typeof r === "function") (this.owner.cleanups ??= []).push(r);
387
388
  });
388
389
  });
389
- reportReactiveNode({ kind: "effect", node: this.computed, handle: this, internal: !report });
390
+ reportReactiveNode({ kind: "effect", node: this.computed, handle: this, internal: !report, ...name ? { name } : {} });
390
391
  this.watcher = new Watcher(() => enqueue(this));
391
392
  this.run();
392
393
  this.watcher.watch(this.computed);
@@ -413,8 +414,8 @@ var EffectNode = class {
413
414
  disposeOwner(this.owner);
414
415
  }
415
416
  };
416
- function effect(fn, report = false) {
417
- const node = new EffectNode(fn, report);
417
+ function effect(fn, report = false, name) {
418
+ const node = new EffectNode(fn, report, name);
418
419
  return () => node.dispose();
419
420
  }
420
421
 
@@ -454,12 +455,12 @@ function createSignal(value, options) {
454
455
  if (isObserved()) onCleanup(() => reportReactiveDispose(state));
455
456
  return [read, write];
456
457
  }
457
- function createEffect(fn, value) {
458
+ function createEffect(fn, value, options) {
458
459
  let prev = value;
459
460
  return effect(() => {
460
461
  const r = fn(prev);
461
462
  prev = r;
462
- }, true);
463
+ }, true, options?.name);
463
464
  }
464
465
  function batch2(fn) {
465
466
  return batch(fn);
@@ -1,5 +1,5 @@
1
1
  // src/version.generated.ts
2
- var VERSION = "1.0.0-alpha.92";
2
+ var VERSION = "1.0.0-alpha.94";
3
3
 
4
4
  // src/lib/signal/graph/state.ts
5
5
  var MAJOR = VERSION.split(".")[0];
@@ -49,11 +49,12 @@ function observeReactiveNodes(next) {
49
49
  }
50
50
  var running = [];
51
51
  var origin;
52
+ var currentScope;
52
53
  function reportReactiveNode(report) {
53
54
  const observer = G.observer;
54
55
  if (observer) {
55
56
  observer.created(
56
- report.parents === void 0 ? { ...report, parents: running, origin: report.origin ?? origin } : report
57
+ report.parents === void 0 ? { ...report, parents: running, origin: report.origin ?? origin, scope: report.scope ?? currentScope } : { ...report, scope: report.scope ?? currentScope }
57
58
  );
58
59
  }
59
60
  }
@@ -347,7 +348,7 @@ function batch(fn) {
347
348
  }
348
349
  }
349
350
  var EffectNode = class {
350
- constructor(fn, report = false) {
351
+ constructor(fn, report = false, name) {
351
352
  this.queued = false;
352
353
  this.disposed = false;
353
354
  this.owner = makeOwner(G.owner);
@@ -359,7 +360,7 @@ var EffectNode = class {
359
360
  if (typeof r === "function") (this.owner.cleanups ??= []).push(r);
360
361
  });
361
362
  });
362
- reportReactiveNode({ kind: "effect", node: this.computed, handle: this, internal: !report });
363
+ reportReactiveNode({ kind: "effect", node: this.computed, handle: this, internal: !report, ...name ? { name } : {} });
363
364
  this.watcher = new Watcher(() => enqueue(this));
364
365
  this.run();
365
366
  this.watcher.watch(this.computed);
@@ -386,8 +387,8 @@ var EffectNode = class {
386
387
  disposeOwner(this.owner);
387
388
  }
388
389
  };
389
- function effect(fn, report = false) {
390
- const node = new EffectNode(fn, report);
390
+ function effect(fn, report = false, name) {
391
+ const node = new EffectNode(fn, report, name);
391
392
  return () => node.dispose();
392
393
  }
393
394
 
@@ -427,12 +428,12 @@ function createSignal(value, options) {
427
428
  if (isObserved()) onCleanup(() => reportReactiveDispose(state));
428
429
  return [read, write];
429
430
  }
430
- function createEffect(fn, value) {
431
+ function createEffect(fn, value, options) {
431
432
  let prev = value;
432
433
  return effect(() => {
433
434
  const r = fn(prev);
434
435
  prev = r;
435
- }, true);
436
+ }, true, options?.name);
436
437
  }
437
438
  function batch2(fn) {
438
439
  return batch(fn);
@@ -27,7 +27,7 @@ __export(derived_exports, {
27
27
  module.exports = __toCommonJS(derived_exports);
28
28
 
29
29
  // src/version.generated.ts
30
- var VERSION = "1.0.0-alpha.92";
30
+ var VERSION = "1.0.0-alpha.94";
31
31
 
32
32
  // src/lib/signal/graph/state.ts
33
33
  var MAJOR = VERSION.split(".")[0];
@@ -77,11 +77,12 @@ function observeReactiveNodes(next) {
77
77
  }
78
78
  var running = [];
79
79
  var origin;
80
+ var currentScope;
80
81
  function reportReactiveNode(report) {
81
82
  const observer = G.observer;
82
83
  if (observer) {
83
84
  observer.created(
84
- report.parents === void 0 ? { ...report, parents: running, origin: report.origin ?? origin } : report
85
+ report.parents === void 0 ? { ...report, parents: running, origin: report.origin ?? origin, scope: report.scope ?? currentScope } : { ...report, scope: report.scope ?? currentScope }
85
86
  );
86
87
  }
87
88
  }
@@ -358,7 +359,7 @@ function afterWrite() {
358
359
  if (G.batchDepth === 0) flushSync();
359
360
  }
360
361
  var EffectNode = class {
361
- constructor(fn, report = false) {
362
+ constructor(fn, report = false, name) {
362
363
  this.queued = false;
363
364
  this.disposed = false;
364
365
  this.owner = makeOwner(G.owner);
@@ -370,7 +371,7 @@ var EffectNode = class {
370
371
  if (typeof r === "function") (this.owner.cleanups ??= []).push(r);
371
372
  });
372
373
  });
373
- reportReactiveNode({ kind: "effect", node: this.computed, handle: this, internal: !report });
374
+ reportReactiveNode({ kind: "effect", node: this.computed, handle: this, internal: !report, ...name ? { name } : {} });
374
375
  this.watcher = new Watcher(() => enqueue(this));
375
376
  this.run();
376
377
  this.watcher.watch(this.computed);
@@ -397,8 +398,8 @@ var EffectNode = class {
397
398
  disposeOwner(this.owner);
398
399
  }
399
400
  };
400
- function effect(fn, report = false) {
401
- const node = new EffectNode(fn, report);
401
+ function effect(fn, report = false, name) {
402
+ const node = new EffectNode(fn, report, name);
402
403
  return () => node.dispose();
403
404
  }
404
405
 
@@ -438,12 +439,12 @@ function createSignal(value, options) {
438
439
  if (isObserved()) onCleanup(() => reportReactiveDispose(state));
439
440
  return [read, write];
440
441
  }
441
- function createEffect(fn, value) {
442
+ function createEffect(fn, value, options) {
442
443
  let prev = value;
443
444
  return effect(() => {
444
445
  const r = fn(prev);
445
446
  prev = r;
446
- }, true);
447
+ }, true, options?.name);
447
448
  }
448
449
 
449
450
  // src/lib/signal/graph/derived.ts
@@ -1,5 +1,5 @@
1
1
  // src/version.generated.ts
2
- var VERSION = "1.0.0-alpha.92";
2
+ var VERSION = "1.0.0-alpha.94";
3
3
 
4
4
  // src/lib/signal/graph/state.ts
5
5
  var MAJOR = VERSION.split(".")[0];
@@ -49,11 +49,12 @@ function observeReactiveNodes(next) {
49
49
  }
50
50
  var running = [];
51
51
  var origin;
52
+ var currentScope;
52
53
  function reportReactiveNode(report) {
53
54
  const observer = G.observer;
54
55
  if (observer) {
55
56
  observer.created(
56
- report.parents === void 0 ? { ...report, parents: running, origin: report.origin ?? origin } : report
57
+ report.parents === void 0 ? { ...report, parents: running, origin: report.origin ?? origin, scope: report.scope ?? currentScope } : { ...report, scope: report.scope ?? currentScope }
57
58
  );
58
59
  }
59
60
  }
@@ -330,7 +331,7 @@ function afterWrite() {
330
331
  if (G.batchDepth === 0) flushSync();
331
332
  }
332
333
  var EffectNode = class {
333
- constructor(fn, report = false) {
334
+ constructor(fn, report = false, name) {
334
335
  this.queued = false;
335
336
  this.disposed = false;
336
337
  this.owner = makeOwner(G.owner);
@@ -342,7 +343,7 @@ var EffectNode = class {
342
343
  if (typeof r === "function") (this.owner.cleanups ??= []).push(r);
343
344
  });
344
345
  });
345
- reportReactiveNode({ kind: "effect", node: this.computed, handle: this, internal: !report });
346
+ reportReactiveNode({ kind: "effect", node: this.computed, handle: this, internal: !report, ...name ? { name } : {} });
346
347
  this.watcher = new Watcher(() => enqueue(this));
347
348
  this.run();
348
349
  this.watcher.watch(this.computed);
@@ -369,8 +370,8 @@ var EffectNode = class {
369
370
  disposeOwner(this.owner);
370
371
  }
371
372
  };
372
- function effect(fn, report = false) {
373
- const node = new EffectNode(fn, report);
373
+ function effect(fn, report = false, name) {
374
+ const node = new EffectNode(fn, report, name);
374
375
  return () => node.dispose();
375
376
  }
376
377
 
@@ -410,12 +411,12 @@ function createSignal(value, options) {
410
411
  if (isObserved()) onCleanup(() => reportReactiveDispose(state));
411
412
  return [read, write];
412
413
  }
413
- function createEffect(fn, value) {
414
+ function createEffect(fn, value, options) {
414
415
  let prev = value;
415
416
  return effect(() => {
416
417
  const r = fn(prev);
417
418
  prev = r;
418
- }, true);
419
+ }, true, options?.name);
419
420
  }
420
421
 
421
422
  // src/lib/signal/graph/derived.ts
@@ -27,7 +27,7 @@ __export(error_boundary_exports, {
27
27
  module.exports = __toCommonJS(error_boundary_exports);
28
28
 
29
29
  // src/version.generated.ts
30
- var VERSION = "1.0.0-alpha.92";
30
+ var VERSION = "1.0.0-alpha.94";
31
31
 
32
32
  // src/lib/signal/graph/state.ts
33
33
  var MAJOR = VERSION.split(".")[0];
@@ -77,11 +77,12 @@ function observeReactiveNodes(next) {
77
77
  }
78
78
  var running = [];
79
79
  var origin;
80
+ var currentScope;
80
81
  function reportReactiveNode(report) {
81
82
  const observer = G.observer;
82
83
  if (observer) {
83
84
  observer.created(
84
- report.parents === void 0 ? { ...report, parents: running, origin: report.origin ?? origin } : report
85
+ report.parents === void 0 ? { ...report, parents: running, origin: report.origin ?? origin, scope: report.scope ?? currentScope } : { ...report, scope: report.scope ?? currentScope }
85
86
  );
86
87
  }
87
88
  }
@@ -1,5 +1,5 @@
1
1
  // src/version.generated.ts
2
- var VERSION = "1.0.0-alpha.92";
2
+ var VERSION = "1.0.0-alpha.94";
3
3
 
4
4
  // src/lib/signal/graph/state.ts
5
5
  var MAJOR = VERSION.split(".")[0];
@@ -49,11 +49,12 @@ function observeReactiveNodes(next) {
49
49
  }
50
50
  var running = [];
51
51
  var origin;
52
+ var currentScope;
52
53
  function reportReactiveNode(report) {
53
54
  const observer = G.observer;
54
55
  if (observer) {
55
56
  observer.created(
56
- report.parents === void 0 ? { ...report, parents: running, origin: report.origin ?? origin } : report
57
+ report.parents === void 0 ? { ...report, parents: running, origin: report.origin ?? origin, scope: report.scope ?? currentScope } : { ...report, scope: report.scope ?? currentScope }
57
58
  );
58
59
  }
59
60
  }
@@ -1,4 +1,4 @@
1
- /*! @fluixi/reactive v1.0.0-alpha.92 | (c) 2026 Ibrahima Touré and Fluixi contributors | MIT */
1
+ /*! @fluixi/reactive v1.0.0-alpha.94 | (c) 2026 Ibrahima Touré and Fluixi contributors | MIT */
2
2
  "use strict";
3
3
  var __defProp = Object.defineProperty;
4
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -29,7 +29,7 @@ __export(index_exports, {
29
29
  module.exports = __toCommonJS(index_exports);
30
30
 
31
31
  // src/version.generated.ts
32
- var VERSION = "1.0.0-alpha.92";
32
+ var VERSION = "1.0.0-alpha.94";
33
33
 
34
34
  // src/lib/signal/graph/state.ts
35
35
  var MAJOR = VERSION.split(".")[0];
@@ -1,7 +1,7 @@
1
- /*! @fluixi/reactive v1.0.0-alpha.92 | (c) 2026 Ibrahima Touré and Fluixi contributors | MIT */
1
+ /*! @fluixi/reactive v1.0.0-alpha.94 | (c) 2026 Ibrahima Touré and Fluixi contributors | MIT */
2
2
 
3
3
  // src/version.generated.ts
4
- var VERSION = "1.0.0-alpha.92";
4
+ var VERSION = "1.0.0-alpha.94";
5
5
 
6
6
  // src/lib/signal/graph/state.ts
7
7
  var MAJOR = VERSION.split(".")[0];
@@ -20,10 +20,15 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/lib/signal/graph/observe.ts
21
21
  var observe_exports = {};
22
22
  __export(observe_exports, {
23
+ adoptReactiveScope: () => adoptReactiveScope,
24
+ closeReactiveScope: () => closeReactiveScope,
23
25
  enterReactiveRun: () => enterReactiveRun,
24
26
  exitReactiveRun: () => exitReactiveRun,
25
27
  isObserved: () => isObserved,
28
+ markReactiveScope: () => markReactiveScope,
26
29
  observeReactiveNodes: () => observeReactiveNodes,
30
+ openReactiveScope: () => openReactiveScope,
31
+ reactiveScopeOf: () => reactiveScopeOf,
27
32
  reportReactiveBinding: () => reportReactiveBinding,
28
33
  reportReactiveContext: () => reportReactiveContext,
29
34
  reportReactiveContextCreated: () => reportReactiveContextCreated,
@@ -34,12 +39,13 @@ __export(observe_exports, {
34
39
  reportReactiveProps: () => reportReactiveProps,
35
40
  reportReactiveRun: () => reportReactiveRun,
36
41
  reportReactiveWrite: () => reportReactiveWrite,
37
- withReactiveOrigin: () => withReactiveOrigin
42
+ withReactiveOrigin: () => withReactiveOrigin,
43
+ withReactiveScope: () => withReactiveScope
38
44
  });
39
45
  module.exports = __toCommonJS(observe_exports);
40
46
 
41
47
  // src/version.generated.ts
42
- var VERSION = "1.0.0-alpha.92";
48
+ var VERSION = "1.0.0-alpha.94";
43
49
 
44
50
  // src/lib/signal/graph/state.ts
45
51
  var MAJOR = VERSION.split(".")[0];
@@ -99,11 +105,40 @@ function withReactiveOrigin(owner, fn) {
99
105
  origin = previous;
100
106
  }
101
107
  }
108
+ var currentScope;
109
+ function openReactiveScope(info) {
110
+ const scope = {};
111
+ G.observer?.scope?.(scope, info, currentScope);
112
+ return scope;
113
+ }
114
+ function withReactiveScope(scope, fn) {
115
+ if (!G.observer) return fn();
116
+ const previous = currentScope;
117
+ currentScope = scope;
118
+ try {
119
+ return fn();
120
+ } finally {
121
+ currentScope = previous;
122
+ }
123
+ }
124
+ function closeReactiveScope(scope) {
125
+ G.observer?.scopeEnded?.(scope);
126
+ }
127
+ function adoptReactiveScope(scope, parent) {
128
+ G.observer?.scopeAdopted?.(scope, parent);
129
+ }
130
+ var SCOPE_OF = /* @__PURE__ */ Symbol.for("fluixi.reactiveScope");
131
+ function markReactiveScope(value, scope) {
132
+ Object.defineProperty(value, SCOPE_OF, { value: scope, configurable: true, enumerable: false });
133
+ }
134
+ function reactiveScopeOf(value) {
135
+ return value !== null && (typeof value === "object" || typeof value === "function") ? value[SCOPE_OF] ?? void 0 : void 0;
136
+ }
102
137
  function reportReactiveNode(report) {
103
138
  const observer = G.observer;
104
139
  if (observer) {
105
140
  observer.created(
106
- report.parents === void 0 ? { ...report, parents: running, origin: report.origin ?? origin } : report
141
+ report.parents === void 0 ? { ...report, parents: running, origin: report.origin ?? origin, scope: report.scope ?? currentScope } : { ...report, scope: report.scope ?? currentScope }
107
142
  );
108
143
  }
109
144
  }
@@ -33,6 +33,22 @@ export interface ReactiveNodeReport {
33
33
  * Live and reused: read it during the call, do not keep it.
34
34
  */
35
35
  parents?: readonly unknown[];
36
+ /**
37
+ * The scope open when this node was made: the custom element, module or service it
38
+ * belongs to. See `openReactiveScope`.
39
+ */
40
+ scope?: object;
41
+ }
42
+ /** What a scope stands for. The graph draws each kind as its own group. */
43
+ export type ReactiveScopeKind = 'element' | 'module' | 'service';
44
+ export interface ReactiveScopeInfo {
45
+ kind: ReactiveScopeKind;
46
+ /** What the author calls it: `<fx-counter>`, `AuthModule`, `AuthService`. */
47
+ name: string;
48
+ /** Something on the page it stands for, such as the element itself, for highlighting. */
49
+ target?: unknown;
50
+ /** One short line of extra detail, such as the token a service was provided for. */
51
+ detail?: string;
36
52
  }
37
53
  export interface ReactiveObserver {
38
54
  created(report: ReactiveNodeReport): void;
@@ -89,6 +105,19 @@ export interface ReactiveObserver {
89
105
  * showing. The watcher reads its own stack for that.
90
106
  */
91
107
  contextCreated?(id: symbol): void;
108
+ /**
109
+ * A scope was opened: a custom element connected, a module registered, a service built.
110
+ * Nothing in the graph says so otherwise; its signals would be loose nodes with no owner
111
+ * a reader recognises. `parent` is the scope open around this one.
112
+ */
113
+ scope?(scope: object, info: ReactiveScopeInfo, parent?: object): void;
114
+ /** A scope ended: the element was removed, the service disposed. */
115
+ scopeEnded?(scope: object): void;
116
+ /**
117
+ * A scope now sits inside another: a service built at import time, later registered by the
118
+ * module that provides it.
119
+ */
120
+ scopeAdopted?(scope: object, parent: object): void;
92
121
  }
93
122
  /**
94
123
  * Watch the graph. Returns a function that stops watching.
@@ -99,6 +128,21 @@ export interface ReactiveObserver {
99
128
  export declare function observeReactiveNodes(next: ReactiveObserver): () => void;
100
129
  /** Attribute everything `fn` creates to `owner`. Free when nobody is watching. */
101
130
  export declare function withReactiveOrigin<T>(owner: unknown, fn: () => T): T;
131
+ /**
132
+ * Announce a scope and get its identity back. Cheap when nobody is watching: an empty
133
+ * object, reported to no one.
134
+ */
135
+ export declare function openReactiveScope(info: ReactiveScopeInfo): object;
136
+ /** Run `fn` with `scope` open, so every node it creates belongs to it. Free when unwatched. */
137
+ export declare function withReactiveScope<T>(scope: object, fn: () => T): T;
138
+ /** The scope has ended. */
139
+ export declare function closeReactiveScope(scope: object): void;
140
+ /** Put an existing scope inside another. */
141
+ export declare function adoptReactiveScope(scope: object, parent: object): void;
142
+ /** Remember `scope` on `value`. Not enumerable, so it never shows up in a spread or a log. */
143
+ export declare function markReactiveScope(value: object, scope: object): void;
144
+ /** The scope a package marked on `value`, if any. */
145
+ export declare function reactiveScopeOf(value: unknown): object | undefined;
102
146
  /** Called by the primitives. Not part of the public surface. */
103
147
  export declare function reportReactiveNode(report: ReactiveNodeReport): void;
104
148
  /** Called around a recompute, so a node can say what it was created inside. */
@@ -1 +1 @@
1
- {"version":3,"file":"observe.d.ts","sourceRoot":"","sources":["../../../../src/lib/signal/graph/observe.ts"],"names":[],"mappings":"AAmBA,MAAM,MAAM,gBAAgB,GAAG,QAAQ,GAAG,MAAM,GAAG,QAAQ,GAAG,OAAO,GAAG,UAAU,CAAC;AAEnF,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,gBAAgB,CAAC;IACvB,oFAAoF;IACpF,IAAI,EAAE,OAAO,CAAC;IACd,iFAAiF;IACjF,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,mDAAmD;IACnD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;;OAIG;IACH,GAAG,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IAC/B;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;;;;;OAOG;IACH,OAAO,CAAC,EAAE,SAAS,OAAO,EAAE,CAAC;CAC9B;AAED,MAAM,WAAW,gBAAgB;IAC/B,OAAO,CAAC,MAAM,EAAE,kBAAkB,GAAG,IAAI,CAAC;IAC1C,6FAA6F;IAC7F,GAAG,CAAC,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,CAAC;IAC1B,0FAA0F;IAC1F,Q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AuF;AACvF,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,GAAG,IAAI,CAEpE;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,OAAO,EACf,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE,MAAM,EACb,QAAQ,CAAC,EAAE,OAAO,GACjB,IAAI,CAMN;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAIxD;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,OAAO,EACf,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,QAAQ,CAAC,EAAE,OAAO,GACjB,IAAI,CAIN;AAED,2FAA2F;AAC3F,wBAAgB,4BAA4B,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAE7D;AAED,6FAA6F;AAC7F,wBAAgB,qBAAqB,CACnC,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,SAAS,GAAG,MAAM,EACxB,KAAK,CAAC,EAAE,OAAO,GACd,IAAI,CAIN;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAEtF;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,CAEzD;AAcD,MAAM,WAAW,YAAY;IAC3B,MAAM,CAAC,CAAC,OAAO,EAAE;QAAE,oBAAoB,EAAE,OAAO,oBAAoB,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;CAChG;AAWD,yFAAyF;AACzF,wBAAgB,UAAU,IAAI,OAAO,CAEpC"}
@@ -46,13 +46,62 @@ export function withReactiveOrigin(owner, fn) {
46
46
  origin = previous;
47
47
  }
48
48
  }
49
+ /** The scope nodes created right now belong to. */
50
+ let currentScope;
51
+ /**
52
+ * Announce a scope and get its identity back. Cheap when nobody is watching: an empty
53
+ * object, reported to no one.
54
+ */
55
+ export function openReactiveScope(info) {
56
+ const scope = {};
57
+ G.observer?.scope?.(scope, info, currentScope);
58
+ return scope;
59
+ }
60
+ /** Run `fn` with `scope` open, so every node it creates belongs to it. Free when unwatched. */
61
+ export function withReactiveScope(scope, fn) {
62
+ if (!G.observer)
63
+ return fn();
64
+ const previous = currentScope;
65
+ currentScope = scope;
66
+ try {
67
+ return fn();
68
+ }
69
+ finally {
70
+ currentScope = previous;
71
+ }
72
+ }
73
+ /** The scope has ended. */
74
+ export function closeReactiveScope(scope) {
75
+ G.observer?.scopeEnded?.(scope);
76
+ }
77
+ /** Put an existing scope inside another. */
78
+ export function adoptReactiveScope(scope, parent) {
79
+ G.observer?.scopeAdopted?.(scope, parent);
80
+ }
81
+ /**
82
+ * Where a package leaves the scope it opened for a value it built, so whoever registers the
83
+ * value later (a module providing it) can place it. Shared by key, across copies.
84
+ */
85
+ const SCOPE_OF = Symbol.for('fluixi.reactiveScope');
86
+ /** Remember `scope` on `value`. Not enumerable, so it never shows up in a spread or a log. */
87
+ export function markReactiveScope(value, scope) {
88
+ Object.defineProperty(value, SCOPE_OF, { value: scope, configurable: true, enumerable: false });
89
+ }
90
+ /** The scope a package marked on `value`, if any. */
91
+ export function reactiveScopeOf(value) {
92
+ return value !== null && (typeof value === 'object' || typeof value === 'function')
93
+ ? (value[SCOPE_OF] ?? undefined)
94
+ : undefined;
95
+ }
49
96
  /** Called by the primitives. Not part of the public surface. */
50
97
  export function reportReactiveNode(report) {
51
98
  const observer = G.observer;
52
99
  // Filled here rather than at each call site: the stack is already on hand, and a report
53
100
  // costs nothing to build when nobody is watching.
54
101
  if (observer) {
55
- observer.created(report.parents === undefined ? { ...report, parents: running, origin: report.origin ?? origin } : report);
102
+ observer.created(report.parents === undefined
103
+ ? { ...report, parents: running, origin: report.origin ?? origin, scope: report.scope ?? currentScope }
104
+ : { ...report, scope: report.scope ?? currentScope });
56
105
  }
57
106
  }
58
107
  /** Called around a recompute, so a node can say what it was created inside. */