@estjs/template 0.0.16-beta.2 → 0.0.16-beta.4

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.
@@ -1,6 +1,6 @@
1
1
  import { Signal, Computed } from '@estjs/signals';
2
- import { S as Scope } from './internal-Bz6h0aPa.cjs';
3
- export { I as InjectionKey, i as inject, p as provide } from './internal-Bz6h0aPa.cjs';
2
+ import { S as Scope } from './internal-DSKAj-zW.cjs';
3
+ export { I as InjectionKey, i as inject, p as provide } from './internal-DSKAj-zW.cjs';
4
4
  import { normalizeClassName } from '@estjs/shared';
5
5
 
6
6
  declare enum COMPONENT_STATE {
@@ -1,6 +1,6 @@
1
1
  import { Signal, Computed } from '@estjs/signals';
2
- import { S as Scope } from './internal-Bz6h0aPa.js';
3
- export { I as InjectionKey, i as inject, p as provide } from './internal-Bz6h0aPa.js';
2
+ import { S as Scope } from './internal-DSKAj-zW.js';
3
+ export { I as InjectionKey, i as inject, p as provide } from './internal-DSKAj-zW.js';
4
4
  import { normalizeClassName } from '@estjs/shared';
5
5
 
6
6
  declare enum COMPONENT_STATE {
@@ -56,8 +56,10 @@ function getActiveScope() {
56
56
  return activeScope;
57
57
  }
58
58
  function createScope(parent = activeScope) {
59
+ const reactiveScope = parent ? parent.effectScope.run(() => signals.effectScope()) : signals.effectScope(true);
59
60
  const scope = {
60
61
  id: ++scopeId,
62
+ effectScope: reactiveScope,
61
63
  parent,
62
64
  children: null,
63
65
  // Lazy initialized
@@ -86,7 +88,7 @@ function runWithScope(scope, fn) {
86
88
  const prevScope = activeScope;
87
89
  activeScope = scope;
88
90
  try {
89
- return fn();
91
+ return scope.effectScope.run(fn);
90
92
  } finally {
91
93
  activeScope = prevScope;
92
94
  }
@@ -106,15 +108,13 @@ function disposeScope(scope) {
106
108
  }
107
109
  scope.children.clear();
108
110
  }
109
- const prevScope = activeScope;
110
- activeScope = scope;
111
- try {
111
+ runWithScope(scope, () => {
112
112
  if (scope.onDestroy) {
113
113
  for (let i = 0; i < scope.onDestroy.length; i++) {
114
114
  try {
115
115
  scope.onDestroy[i]();
116
116
  } catch (error_) {
117
- if (true) {
117
+ {
118
118
  shared.error(`Scope(${scope.id}): Error in destroy hook:`, error_);
119
119
  }
120
120
  }
@@ -126,16 +126,15 @@ function disposeScope(scope) {
126
126
  try {
127
127
  scope.cleanup[i]();
128
128
  } catch (error_) {
129
- if (true) {
129
+ {
130
130
  shared.error(`Scope(${scope.id}): Error in cleanup:`, error_);
131
131
  }
132
132
  }
133
133
  }
134
134
  scope.cleanup = null;
135
135
  }
136
- } finally {
137
- activeScope = prevScope;
138
- }
136
+ });
137
+ scope.effectScope.stop();
139
138
  if ((_a2 = scope.parent) == null ? void 0 : _a2.children) {
140
139
  scope.parent.children.delete(scope);
141
140
  }
@@ -692,7 +691,7 @@ function normalizeNode(node) {
692
691
  }
693
692
  function insert(parent, nodeFactory, before) {
694
693
  if (!parent) return;
695
- const ownerScope = getActiveScope();
694
+ const parentScope = getActiveScope();
696
695
  let renderedNodes = [];
697
696
  let isFirstRun = true;
698
697
  const resolveNodes = (raw) => {
@@ -716,8 +715,8 @@ function insert(parent, nodeFactory, before) {
716
715
  renderedNodes = reconcileArrays(parent, renderedNodes, nodes, before);
717
716
  isFirstRun = false;
718
717
  };
719
- if (ownerScope && !ownerScope.isDestroyed) {
720
- runWithScope(ownerScope, executeUpdate);
718
+ if (parentScope && !parentScope.isDestroyed) {
719
+ runWithScope(parentScope, executeUpdate);
721
720
  } else {
722
721
  executeUpdate();
723
722
  }
@@ -918,7 +917,9 @@ var Component = class {
918
917
  if (shared.isFunction(result)) {
919
918
  result = result(this.reactiveProps);
920
919
  }
921
- if (signals.isSignal(result) || signals.isComputed(result)) {
920
+ if (signals.isSignal(result)) {
921
+ result = result.value;
922
+ } else if (signals.isComputed(result)) {
922
923
  result = result.value;
923
924
  }
924
925
  return (_a3 = insert(parentNode, result, beforeNode)) != null ? _a3 : [];
@@ -1019,11 +1020,12 @@ var Component = class {
1019
1020
  return () => value(null);
1020
1021
  }
1021
1022
  if (signals.isSignal(value)) {
1022
- const previousValue = value.value;
1023
- value.value = root;
1023
+ const ref = value;
1024
+ const previousValue = ref.value;
1025
+ ref.value = root;
1024
1026
  return () => {
1025
- if (value.value === root) {
1026
- value.value = previousValue;
1027
+ if (ref.value === root) {
1028
+ ref.value = previousValue;
1027
1029
  }
1028
1030
  };
1029
1031
  }
@@ -1449,10 +1451,10 @@ function Portal(props) {
1449
1451
  placeholder[PORTAL_COMPONENT] = true;
1450
1452
  const { children } = props;
1451
1453
  if (children == null) return placeholder;
1452
- const ownerScope = getActiveScope();
1454
+ const parentScope = getActiveScope();
1453
1455
  let innerScope = null;
1454
1456
  const mountAt = (parent, before) => {
1455
- innerScope = createScope(ownerScope);
1457
+ innerScope = createScope(parentScope);
1456
1458
  runWithScope(innerScope, () => {
1457
1459
  insert(parent, () => children, before);
1458
1460
  });