@pravosleva/reactive-engine 1.7.0-beta → 1.8.0-beta
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.
- package/dist/angular/ReactiveEngine4Angular.cjs +1 -1
- package/dist/angular/ReactiveEngine4Angular.cjs.map +1 -1
- package/dist/angular/ReactiveEngine4Angular.d.ts +16 -7
- package/dist/angular/ReactiveEngine4Angular.d.ts.map +1 -1
- package/dist/angular/ReactiveEngine4Angular.mjs +4 -4
- package/dist/angular/ReactiveEngine4Angular.mjs.map +1 -1
- package/dist/angular/core.angular.auto.test.d.ts +2 -0
- package/dist/angular/core.angular.auto.test.d.ts.map +1 -0
- package/dist/angular/core.angular.test.d.ts +2 -0
- package/dist/angular/core.angular.test.d.ts.map +1 -0
- package/dist/angular/index.cjs +1 -1
- package/dist/angular/index.d.ts +2 -2
- package/dist/angular/index.d.ts.map +1 -1
- package/dist/angular/index.mjs +1 -1
- package/dist/angular/rxjs-interop.d.ts +1 -1
- package/dist/angular/rxjs-interop.d.ts.map +1 -1
- package/dist/core/AbstractService.d.ts +3 -3
- package/dist/core/core.auto.test.d.ts +2 -0
- package/dist/core/core.auto.test.d.ts.map +1 -0
- package/dist/core/core.d.ts +105 -366
- package/dist/core/core.d.ts.map +1 -1
- package/dist/core/types.d.ts +102 -72
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core.cjs +1 -1
- package/dist/core.cjs.map +1 -1
- package/dist/core.mjs +497 -414
- package/dist/core.mjs.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +11 -11
- package/dist/react/ReactiveEngine4React.cjs +1 -1
- package/dist/react/ReactiveEngine4React.cjs.map +1 -1
- package/dist/react/ReactiveEngine4React.d.ts +16 -8
- package/dist/react/ReactiveEngine4React.d.ts.map +1 -1
- package/dist/react/ReactiveEngine4React.mjs +5 -5
- package/dist/react/ReactiveEngine4React.mjs.map +1 -1
- package/dist/react/core.react.auto.test.d.ts +2 -0
- package/dist/react/core.react.auto.test.d.ts.map +1 -0
- package/dist/react/hooks/FilteredCatalog.auto.test.d.ts +2 -0
- package/dist/react/hooks/FilteredCatalog.auto.test.d.ts.map +1 -0
- package/dist/react/hooks/useReactiveSubscription/useReactiveSubscription.auto.test.d.ts +2 -0
- package/dist/react/hooks/useReactiveSubscription/useReactiveSubscription.auto.test.d.ts.map +1 -0
- package/dist/react/hooks/useReactiveValue/useReactiveValue.auto.test.d.ts +2 -0
- package/dist/react/hooks/useReactiveValue/useReactiveValue.auto.test.d.ts.map +1 -0
- package/dist/react/index.cjs +1 -1
- package/dist/react/index.d.ts +2 -2
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.mjs +1 -1
- package/dist/reactive-engine.umd.js +2 -2
- package/dist/reactive-engine.umd.js.map +1 -1
- package/dist/vue/ReactiveEngine4Vue.cjs +1 -1
- package/dist/vue/ReactiveEngine4Vue.cjs.map +1 -1
- package/dist/vue/ReactiveEngine4Vue.d.ts +21 -13
- package/dist/vue/ReactiveEngine4Vue.d.ts.map +1 -1
- package/dist/vue/ReactiveEngine4Vue.mjs +27 -17
- package/dist/vue/ReactiveEngine4Vue.mjs.map +1 -1
- package/dist/vue/composables/useReactiveValue.auto.test.d.ts +2 -0
- package/dist/vue/composables/useReactiveValue.auto.test.d.ts.map +1 -0
- package/dist/vue/core.vue.auto.test.d.ts +2 -0
- package/dist/vue/core.vue.auto.test.d.ts.map +1 -0
- package/dist/vue/core.vue.test.d.ts +2 -0
- package/dist/vue/core.vue.test.d.ts.map +1 -0
- package/dist/vue/index.cjs +1 -1
- package/dist/vue/index.d.ts +1 -1
- package/dist/vue/index.d.ts.map +1 -1
- package/dist/vue/index.mjs +1 -1
- package/package.json +1 -1
- package/dist/angular/ReactiveEngine4Angular.test.d.ts +0 -2
- package/dist/angular/ReactiveEngine4Angular.test.d.ts.map +0 -1
- package/dist/decorators/withThrottleComputed/_withThrottleComputed.d.ts +0 -22
- package/dist/decorators/withThrottleComputed/_withThrottleComputed.d.ts.map +0 -1
- package/dist/utils/getExtractedValues.cjs +0 -2
- package/dist/utils/getExtractedValues.cjs.map +0 -1
- package/dist/utils/getExtractedValues.mjs +0 -24
- package/dist/utils/getExtractedValues.mjs.map +0 -1
- package/dist/vue/ReactiveEngine4Vue.test.d.ts +0 -2
- package/dist/vue/ReactiveEngine4Vue.test.d.ts.map +0 -1
package/dist/core.mjs
CHANGED
|
@@ -1,280 +1,189 @@
|
|
|
1
|
-
import { getExtractedValues as e } from "./utils/getExtractedValues.mjs";
|
|
2
1
|
//#region src/core/core.ts
|
|
3
|
-
var
|
|
2
|
+
var e = class {
|
|
4
3
|
frameworkPrefix = "core";
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
activeConsumer = null;
|
|
5
|
+
subscriberId = 0;
|
|
6
|
+
batchDepth = 0;
|
|
7
7
|
pendingEffects = /* @__PURE__ */ new Set();
|
|
8
|
-
services = /* @__PURE__ */ new Map();
|
|
9
|
-
factories = /* @__PURE__ */ new Map();
|
|
10
|
-
proxyCache = /* @__PURE__ */ new WeakMap();
|
|
11
8
|
allEffects = /* @__PURE__ */ new Set();
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
batchTickCounts = 0;
|
|
19
|
-
constructor(e) {
|
|
20
|
-
this.loggerOptions = e?.logger;
|
|
21
|
-
}
|
|
22
|
-
log(t, n, r) {
|
|
23
|
-
if (!this.loggerOptions?.isEnabled) return;
|
|
24
|
-
if (!this.loggerOptions?.isCoreOptimizationDebugEnabled) {
|
|
25
|
-
let t = e({
|
|
26
|
-
expectedKey: "CORE_INTERNAL_SIGNAL",
|
|
27
|
-
tested: [n],
|
|
28
|
-
valueType: "number"
|
|
29
|
-
})?.[0] === "1", r = e({
|
|
30
|
-
expectedKey: "CORE_INTERNAL_EFFECT",
|
|
31
|
-
tested: [n],
|
|
32
|
-
valueType: "number"
|
|
33
|
-
})?.[0] === "1";
|
|
34
|
-
if (t || r) return;
|
|
9
|
+
computedCache = /* @__PURE__ */ new Map();
|
|
10
|
+
computed(e, t) {
|
|
11
|
+
let n = this;
|
|
12
|
+
if (n.computedCache.has(e)) {
|
|
13
|
+
let t = n.computedCache.get(e)?.deref();
|
|
14
|
+
if (t) return t;
|
|
35
15
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}, a = "", o = "color: #aaa; font-weight: normal;";
|
|
45
|
-
switch (t) {
|
|
46
|
-
case "signal": {
|
|
47
|
-
let s = e({
|
|
48
|
-
tested: [n],
|
|
49
|
-
expectedKey: "CORE_INTERNAL_SIGNAL",
|
|
50
|
-
valueType: "number"
|
|
51
|
-
})?.[0] === "1", c = n, l = (this.signalMutationCounts.get(c) || 0) + 1;
|
|
52
|
-
this.signalMutationCounts.set(c, l);
|
|
53
|
-
let u = r, d = u.subscribers && u.subscribers.length > 0 ? u.subscribers.every((t) => t ? e({
|
|
54
|
-
tested: [t],
|
|
55
|
-
expectedKey: "IS_OPTIMIZED",
|
|
56
|
-
valueType: "number"
|
|
57
|
-
})?.[0] === "1" : !1) : !1, f = l > 50, p = s ? "COMPUTED_INTERNAL" : "SIGNAL";
|
|
58
|
-
a = ` 🔄 Изменений ${s ? "кэша" : "сигнала"}: ${l}${f ? " ⚠️ (high noise — обнаружен дребезг/спам значений!)" : ""}`, f && (o = "color: orange; font-weight: bold;", d || (r.__performance_advice__ = {
|
|
59
|
-
issue: `Сигнал [${c}] обновляется слишком часто (${l} раз за такт). Это приводит к избыточным ререндерам UI.`,
|
|
60
|
-
solution: "Оберните чтение этого сигнала в декоратор сжатия потока данных 'withThrottleComputed'",
|
|
61
|
-
example: "public throttled = withThrottleComputed(this.engine, () => this.yourSignalName.value, { limit: 300 });"
|
|
62
|
-
})), console.groupCollapsed(`%c${p}%c [${c}]%c${a}`, s ? "background: #42b883; color: #fff; padding: 2px 6px; border-radius: 4px; font-weight: bold;" : i[t], "color: #aaa; font-weight: bold;", o), console.log("Данные (Payload):", r), this.loggerOptions.traceTime && typeof performance < "u" && console.log("Тайминг рантайма:", `${performance.now().toFixed(2)} ms`), console.groupEnd();
|
|
63
|
-
return;
|
|
16
|
+
let r = t || "unnamed_computed", i, a = /* @__PURE__ */ new Set(), o = {
|
|
17
|
+
id: ++n.subscriberId,
|
|
18
|
+
isDirty: !0,
|
|
19
|
+
cleanups: /* @__PURE__ */ new Set(),
|
|
20
|
+
markDirty() {
|
|
21
|
+
this.isDirty || (this.isDirty = !0, Array.from(a).forEach((e) => {
|
|
22
|
+
e !== n.activeConsumer && e.markDirty();
|
|
23
|
+
}));
|
|
64
24
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
if (
|
|
68
|
-
let
|
|
69
|
-
a
|
|
70
|
-
} else if (e && "duration" in e) {
|
|
71
|
-
let t = parseFloat(e.duration);
|
|
72
|
-
if (!isNaN(t)) {
|
|
73
|
-
let r = this.lastComputedDurations.get(n);
|
|
74
|
-
if (r !== void 0 && r > 0) {
|
|
75
|
-
let n = (t - r) / r * 100;
|
|
76
|
-
n > 5 ? (a = ` 🔴 Замедление: +${n.toFixed(1)}% (${e.duration})`, o = "color: #e01e5a; font-weight: bold;") : n < -5 ? (a = ` 🟢 Ускорение: ${n.toFixed(1)}% (${e.duration})`, o = "color: #42b883; font-weight: bold;") : (a = ` 🟢 Стабильно (${e.duration})`, o = "color: #42b883; font-weight: bold;");
|
|
77
|
-
} else a = ` ⚪ Первый расчет (${e.duration})`;
|
|
78
|
-
this.lastComputedDurations.set(n, t);
|
|
79
|
-
}
|
|
25
|
+
}, s = {
|
|
26
|
+
get value() {
|
|
27
|
+
if (n.activeConsumer) {
|
|
28
|
+
let e = n.activeConsumer;
|
|
29
|
+
a.has(e) || (a.add(e), e.cleanups.add(() => a.delete(e)));
|
|
80
30
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
this.batchTickCounts += 1, a = ` 📦 Номер транзакции: #${this.batchTickCounts}`;
|
|
92
|
-
break;
|
|
93
|
-
case "resource": {
|
|
94
|
-
let e = r;
|
|
95
|
-
if (e.loading) a = " ⏳ ЗАГРУЗКА (fetching...)", o = "color: #d97706; font-weight: bold;";
|
|
96
|
-
else if (e.error) a = ` 🔴 ОШИБКА: ${e.error.message || "Unknown Error"}`, o = "color: #ff4a4a; font-weight: bold;";
|
|
97
|
-
else {
|
|
98
|
-
let t = e.data;
|
|
99
|
-
a = ` 🟢 УСПЕХ (data: ${typeof t == "object" && t ? "{...}" : String(t)})`, o = "color: #42b883; font-weight: bold;";
|
|
31
|
+
if (o.isDirty) {
|
|
32
|
+
let t = Array.from(o.cleanups);
|
|
33
|
+
o.cleanups.clear(), t.forEach((e) => e());
|
|
34
|
+
let r = n.activeConsumer;
|
|
35
|
+
n.activeConsumer = o;
|
|
36
|
+
try {
|
|
37
|
+
i = e(), o.isDirty = !1;
|
|
38
|
+
} finally {
|
|
39
|
+
n.activeConsumer = r;
|
|
40
|
+
}
|
|
100
41
|
}
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
provide(e, t) {
|
|
109
|
-
typeof t == "function" && !t.prototype ? this.factories.set(e, t) : this.services.set(e, t);
|
|
110
|
-
}
|
|
111
|
-
inject(e) {
|
|
112
|
-
if (!e) throw Error("[DI Error]: Вы пытаетесь внедрить пустой токен (undefined/null). Проверьте импорты.");
|
|
113
|
-
let t = e;
|
|
114
|
-
if (this.services.has(t)) return this.services.get(t);
|
|
115
|
-
try {
|
|
116
|
-
let n = this.factories.get(t);
|
|
117
|
-
if (n) {
|
|
118
|
-
let e = n(this);
|
|
119
|
-
return this.services.set(t, e), e;
|
|
120
|
-
}
|
|
121
|
-
if (typeof e == "function" && e.prototype) {
|
|
122
|
-
let n = new e(this);
|
|
123
|
-
return this.services.set(t, n), n;
|
|
42
|
+
return i;
|
|
43
|
+
},
|
|
44
|
+
subscribe: (e) => n.effect(() => e(s.value), `computed:use:${r}`),
|
|
45
|
+
destroy() {
|
|
46
|
+
let t = Array.from(o.cleanups);
|
|
47
|
+
o.cleanups.clear(), t.forEach((e) => e()), a.clear(), n.computedCache.delete(e);
|
|
48
|
+
for (let [e, t] of n.computedCache.entries()) t.deref() === s && n.computedCache.delete(e);
|
|
124
49
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
throw Error(`[DI Error]: Не удалось создать сервис ${String(e)}. Ошибка: ${t?.message || "No e?.message"}`);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
queueLog(e, t, n) {
|
|
131
|
-
this.loggerOptions?.isEnabled && this.pendingLogQueue.push({
|
|
132
|
-
type: e,
|
|
133
|
-
name: t,
|
|
134
|
-
detail: n
|
|
135
|
-
});
|
|
50
|
+
};
|
|
51
|
+
return n.cleanupRegistry && n.cleanupRegistry.register(s, () => s.destroy()), n.computedCache.set(e, new WeakRef(s)), s;
|
|
136
52
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
53
|
+
effect(e, t) {
|
|
54
|
+
let n = this, r = {
|
|
55
|
+
id: ++n.subscriberId,
|
|
56
|
+
label: t,
|
|
57
|
+
cleanups: /* @__PURE__ */ new Set(),
|
|
58
|
+
markDirty() {
|
|
59
|
+
n.pendingEffects.add(r), n.batchDepth === 0 && n.flushEffects();
|
|
60
|
+
},
|
|
61
|
+
run() {
|
|
62
|
+
let t = Array.from(r.cleanups);
|
|
63
|
+
r.cleanups.clear(), t.forEach((e) => {
|
|
64
|
+
try {
|
|
65
|
+
e();
|
|
66
|
+
} catch (e) {
|
|
67
|
+
console.error("[Reactive Engine:Cleanup Error]", e);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
let i = n.activeConsumer;
|
|
71
|
+
n.activeConsumer = r;
|
|
72
|
+
try {
|
|
73
|
+
let t = e();
|
|
74
|
+
typeof t == "function" && r.cleanups.add(t);
|
|
75
|
+
} catch (e) {
|
|
76
|
+
console.error("[Reactive Error] Ошибка при выполнении тела эффекта:", e);
|
|
77
|
+
} finally {
|
|
78
|
+
n.activeConsumer = i;
|
|
79
|
+
}
|
|
146
80
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
let t = performance.now() - e;
|
|
158
|
-
if (n = ` | Duration: ${t.toFixed(3)} ms`, this.lastTransactionDuration !== null && this.lastTransactionDuration > 0) {
|
|
159
|
-
let e = (t - this.lastTransactionDuration) / this.lastTransactionDuration * 100;
|
|
160
|
-
e > .1 ? (r = ` 🔴 +${e.toFixed(1)}%`, i = "color: #e01e5a; font-weight: bold;") : e < -.1 ? (r = ` 🟢 ${e.toFixed(1)}%`, i = "color: #42b883; font-weight: bold;") : (r = " 🟢 stable", i = "color: #42b883; font-weight: bold;");
|
|
161
|
-
} else r = " ⚪ first";
|
|
162
|
-
this.lastTransactionDuration = t;
|
|
163
|
-
}
|
|
164
|
-
console.groupCollapsed(`%cREACTIVE TRANSACTION${this.loggerOptions.instanceName ? ` ${this.loggerOptions.instanceName}` : ""}%c Microtask Tick (Size: ${t.length}${n})%c${r}`, "background: #7952b3; color: #fff; padding: 2px 6px; border-radius: 4px; font-weight: bold;", "color: #aaa; font-weight: normal;", i), t.forEach((e) => {
|
|
165
|
-
this.log(e.type, e.name, e.detail);
|
|
166
|
-
}), this.loggerOptions.traceTime && typeof performance < "u" && console.log(`%c[Execution Timestamp]: ${performance.now().toFixed(2)} ms`, "color: #7952b3; font-weight: bold;"), console.groupEnd(), this.pendingLogQueue = [];
|
|
81
|
+
};
|
|
82
|
+
return n.allEffects.add(r), r.run(), () => {
|
|
83
|
+
Array.from(r.cleanups).forEach((e) => {
|
|
84
|
+
try {
|
|
85
|
+
e();
|
|
86
|
+
} catch (e) {
|
|
87
|
+
console.error("[Reactive Engine:Dispose Cleanup Error]", e);
|
|
88
|
+
}
|
|
89
|
+
}), r.cleanups.clear(), n.pendingEffects.delete(r), n.allEffects.delete(r);
|
|
90
|
+
};
|
|
167
91
|
}
|
|
168
92
|
signal(e, t) {
|
|
169
93
|
let n = this, r = e, i = /* @__PURE__ */ new Set(), a = typeof t == "string" ? { name: t } : t || {}, o = a.name || "unnamed_signal";
|
|
170
94
|
return {
|
|
171
95
|
get value() {
|
|
172
|
-
if (n.
|
|
173
|
-
let e = n.
|
|
174
|
-
i.has(e) || (i.add(e), e.cleanups.add(() =>
|
|
175
|
-
i.delete(e);
|
|
176
|
-
}));
|
|
96
|
+
if (n.activeConsumer) {
|
|
97
|
+
let e = n.activeConsumer;
|
|
98
|
+
i.has(e) || (i.add(e), e.cleanups.add(() => i.delete(e)));
|
|
177
99
|
}
|
|
178
100
|
return r;
|
|
179
101
|
},
|
|
180
102
|
set value(e) {
|
|
181
|
-
if (a?.validate
|
|
103
|
+
if (a?.validate) {
|
|
182
104
|
let t = a.validate(e);
|
|
183
|
-
|
|
184
|
-
|
|
105
|
+
if (t !== !0) {
|
|
106
|
+
console.error(`[Reactive Engine: Validation Error] ${t}`);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
185
109
|
}
|
|
186
110
|
if ((e === null || typeof e != "object" && typeof e != "function") && r === e) return;
|
|
187
111
|
let t = r;
|
|
188
|
-
r = e, n.onSignalChange?.(o, e, t), i.forEach((e) => {
|
|
189
|
-
e !== n.
|
|
190
|
-
for (let e of n.pendingEffects) n.pendingEffects.delete(e), e.run();
|
|
191
|
-
n.isBatching = !1, n.flushLogs?.();
|
|
192
|
-
}))));
|
|
112
|
+
r = e, n.onSignalChange?.(o, e, t), Array.from(i).forEach((e) => {
|
|
113
|
+
e !== n.activeConsumer && e.markDirty();
|
|
193
114
|
});
|
|
194
115
|
},
|
|
195
116
|
subscribe(e) {
|
|
196
|
-
return n.effect(() => {
|
|
197
|
-
e(this.value);
|
|
198
|
-
}, `${n.frameworkPrefix}:use:${o}`);
|
|
117
|
+
return n.effect(() => e(this.value), `use:${o}`);
|
|
199
118
|
}
|
|
200
119
|
};
|
|
201
120
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
let i = n.activeEffect;
|
|
210
|
-
n.activeEffect = this;
|
|
211
|
-
let a = performance.now();
|
|
212
|
-
n.safeRun(this, () => {
|
|
213
|
-
let t = e();
|
|
214
|
-
typeof t == "function" && this.cleanups.add(t);
|
|
215
|
-
}), n.activeEffect = i;
|
|
216
|
-
let o = performance.now() - a;
|
|
217
|
-
if (!r && n.loggerOptions?.isEnabled) {
|
|
218
|
-
let e = n.loggerOptions.filter;
|
|
219
|
-
(!e || e instanceof RegExp && this.label && e.test(this.label)) && typeof n.queueLog == "function" && n.queueLog("effect", this.label || "unnamed-efect-0", {
|
|
220
|
-
name: this.label || "unnamed-efect-0",
|
|
221
|
-
type: "effect",
|
|
222
|
-
detail: {
|
|
223
|
-
status: "stable",
|
|
224
|
-
duration: `${o.toFixed(3)}ms`,
|
|
225
|
-
timestamp: a
|
|
226
|
-
}
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
r = !1;
|
|
230
|
-
}
|
|
231
|
-
};
|
|
232
|
-
return this.allEffects.add(i), i.run(), () => {
|
|
233
|
-
i.cleanups.forEach((e) => e()), n.pendingEffects.delete(i), n.allEffects.delete(i);
|
|
234
|
-
};
|
|
121
|
+
batch(e) {
|
|
122
|
+
this.batchDepth++;
|
|
123
|
+
try {
|
|
124
|
+
e();
|
|
125
|
+
} finally {
|
|
126
|
+
this.batchDepth--, this.batchDepth === 0 && this.flushEffects();
|
|
127
|
+
}
|
|
235
128
|
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
e()
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
129
|
+
flushEffects() {
|
|
130
|
+
let e = Array.from(this.pendingEffects);
|
|
131
|
+
this.pendingEffects.clear(), e.forEach((e) => {
|
|
132
|
+
e.run();
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
untrack(e) {
|
|
136
|
+
let t = this.activeConsumer;
|
|
137
|
+
this.activeConsumer = null;
|
|
138
|
+
try {
|
|
139
|
+
return e();
|
|
140
|
+
} finally {
|
|
141
|
+
this.activeConsumer = t;
|
|
244
142
|
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
destroy() {
|
|
260
|
-
s(), l(), n.computedCache.delete(e);
|
|
261
|
-
}
|
|
262
|
-
};
|
|
263
|
-
return this.cleanupRegistry.register(u, l), this.computedCache.set(e, new WeakRef(u)), u;
|
|
143
|
+
}
|
|
144
|
+
}, t = class extends e {
|
|
145
|
+
services = /* @__PURE__ */ new Map();
|
|
146
|
+
factories = /* @__PURE__ */ new Map();
|
|
147
|
+
proxyCache = /* @__PURE__ */ new WeakMap();
|
|
148
|
+
loggerOptions;
|
|
149
|
+
pendingLogQueue = [];
|
|
150
|
+
signalMutationCounts = /* @__PURE__ */ new Map();
|
|
151
|
+
lastComputedDurations = /* @__PURE__ */ new Map();
|
|
152
|
+
effectExecutionCounts = /* @__PURE__ */ new Map();
|
|
153
|
+
batchTickCounts = 0;
|
|
154
|
+
lastTransactionDuration = null;
|
|
155
|
+
constructor(e) {
|
|
156
|
+
super(), this.loggerOptions = e?.logger;
|
|
264
157
|
}
|
|
265
158
|
reactive(e, t = "reactive") {
|
|
266
159
|
if (this.proxyCache.has(e)) return this.proxyCache.get(e);
|
|
267
|
-
let n = this, r = /* @__PURE__ */ new Map(), i = new Proxy(e, {
|
|
268
|
-
get(e,
|
|
269
|
-
if (
|
|
270
|
-
let
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
160
|
+
let n = this, r = /* @__PURE__ */ new Map(), i = !1, a = new Proxy(e, {
|
|
161
|
+
get(e, o, s) {
|
|
162
|
+
if (o === "__subscribe") return (e) => {
|
|
163
|
+
let t = !1;
|
|
164
|
+
return n.effect(() => {
|
|
165
|
+
try {
|
|
166
|
+
JSON.stringify(a);
|
|
167
|
+
} catch {
|
|
168
|
+
Object.values(a);
|
|
169
|
+
}
|
|
170
|
+
typeof window < "u" && (window.__VUE__ || globalThis.__VUE__ || e.toString().includes("triggerRef")) ? t || (t = !0, queueMicrotask(() => {
|
|
171
|
+
t = !1, e();
|
|
172
|
+
})) : e();
|
|
173
|
+
}, "framework-proxy-internal-subscription");
|
|
174
|
+
};
|
|
175
|
+
if (n.activeConsumer) {
|
|
176
|
+
let e = n.activeConsumer;
|
|
177
|
+
r.has(o) || r.set(o, /* @__PURE__ */ new Map());
|
|
178
|
+
let t = r.get(o);
|
|
179
|
+
if (!t.has(e)) {
|
|
180
|
+
let n = () => {
|
|
181
|
+
t.delete(e);
|
|
182
|
+
};
|
|
183
|
+
t.set(e, n), e.cleanups.add(n);
|
|
184
|
+
}
|
|
276
185
|
}
|
|
277
|
-
if (Array.isArray(e) && typeof
|
|
186
|
+
if (Array.isArray(e) && typeof o == "string" && [
|
|
278
187
|
"push",
|
|
279
188
|
"pop",
|
|
280
189
|
"shift",
|
|
@@ -282,220 +191,394 @@ var t = class {
|
|
|
282
191
|
"splice",
|
|
283
192
|
"sort",
|
|
284
193
|
"reverse"
|
|
285
|
-
].includes(
|
|
286
|
-
let t = e[
|
|
194
|
+
].includes(o)) {
|
|
195
|
+
let t = e[o];
|
|
287
196
|
return function(...a) {
|
|
288
|
-
|
|
289
|
-
n.isBatching = !0;
|
|
197
|
+
n.batchDepth++, i = !0;
|
|
290
198
|
let s = t.apply(e, a);
|
|
291
|
-
return r.forEach((e, t) => {
|
|
292
|
-
t !==
|
|
293
|
-
e !== n.
|
|
199
|
+
return i = !1, r.forEach((e, t) => {
|
|
200
|
+
t !== o && Array.from(e.keys()).forEach((e) => {
|
|
201
|
+
e !== n.activeConsumer && e.markDirty();
|
|
294
202
|
});
|
|
295
|
-
}), n.
|
|
296
|
-
for (let e of n.pendingEffects) n.pendingEffects.delete(e), e.run();
|
|
297
|
-
n.isBatching = !1, n.flushLogs?.();
|
|
298
|
-
})), s;
|
|
203
|
+
}), n.batchDepth--, n.batchDepth === 0 && n.flushEffects(), s;
|
|
299
204
|
};
|
|
300
205
|
}
|
|
301
|
-
let
|
|
302
|
-
return typeof
|
|
206
|
+
let c = Reflect.get(e, o, s);
|
|
207
|
+
return typeof c == "object" && c ? n.reactive(c, `${t}.${String(o)}`) : c;
|
|
303
208
|
},
|
|
304
|
-
set(e,
|
|
305
|
-
let
|
|
306
|
-
if (
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
let
|
|
310
|
-
|
|
311
|
-
let e = r.get("length");
|
|
312
|
-
e && l.push(...Array.from(e));
|
|
313
|
-
}
|
|
314
|
-
l.forEach((e) => {
|
|
315
|
-
e !== n.activeEffect && (n.isBatching ? n.pendingEffects.add(e) : (n.pendingEffects.add(e), n.isBatching || (n.isBatching = !0, queueMicrotask(() => {
|
|
316
|
-
for (let e of n.pendingEffects) n.pendingEffects.delete(e), e.run();
|
|
317
|
-
n.isBatching = !1, n.flushLogs?.();
|
|
318
|
-
}))));
|
|
319
|
-
}), n.queueLog?.("reactive", `${t}.${String(i)}`, {
|
|
320
|
-
action: "set",
|
|
321
|
-
property: String(i),
|
|
322
|
-
oldValue: s,
|
|
323
|
-
newValue: a
|
|
324
|
-
});
|
|
209
|
+
set(e, a, o, s) {
|
|
210
|
+
let c = Reflect.get(e, a, s);
|
|
211
|
+
if (c === o || (Reflect.set(e, a, o, s), n.onSignalChange?.(`${t}.${String(a)}`, o, c), i)) return !0;
|
|
212
|
+
let l = r.get(a), u = l ? Array.from(l.keys()) : [];
|
|
213
|
+
if (Array.isArray(e)) {
|
|
214
|
+
let e = r.get("length");
|
|
215
|
+
e && u.push(...Array.from(e.keys()));
|
|
325
216
|
}
|
|
326
|
-
return
|
|
217
|
+
return u.forEach((e) => {
|
|
218
|
+
e !== n.activeConsumer && e.markDirty();
|
|
219
|
+
}), typeof n.queueLog == "function" && n.queueLog("reactive", `${t}.${String(a)}`, {
|
|
220
|
+
action: "set",
|
|
221
|
+
property: String(a),
|
|
222
|
+
oldValue: c,
|
|
223
|
+
newValue: o
|
|
224
|
+
}), !0;
|
|
327
225
|
}
|
|
328
226
|
});
|
|
329
|
-
return this.proxyCache.set(e,
|
|
227
|
+
return this.proxyCache.set(e, a), a;
|
|
330
228
|
}
|
|
331
|
-
|
|
332
|
-
e();
|
|
229
|
+
provide(e, t) {
|
|
230
|
+
typeof t == "function" && (!t.prototype || t.name === "mockConstructor" || t._isMockFunction) ? this.factories.set(e, t) : this.services.set(e, t);
|
|
333
231
|
}
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
232
|
+
inject(e) {
|
|
233
|
+
if (!e) throw Error("[DI Error]: Вы пытаетесь внедрить пустой токен.");
|
|
234
|
+
let t = e;
|
|
235
|
+
if (this.services.has(t)) return this.services.get(t);
|
|
236
|
+
try {
|
|
237
|
+
let n = this.factories.get(t);
|
|
238
|
+
if (n) {
|
|
239
|
+
let e = n(this);
|
|
240
|
+
return this.services.set(t, e), e;
|
|
241
|
+
}
|
|
242
|
+
if (typeof e == "function" && e.prototype) {
|
|
243
|
+
let n = new e(this);
|
|
244
|
+
return this.services.set(t, n), n;
|
|
245
|
+
}
|
|
246
|
+
throw Error(`Service not found: ${String(e)}`);
|
|
247
|
+
} catch {
|
|
248
|
+
throw Error(`[DI Error]: Не удалось создать сервис ${String(e)}.`);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
queueLog(e, t, n) {
|
|
252
|
+
this.loggerOptions?.isEnabled && (this.pendingLogQueue.push({
|
|
253
|
+
type: e,
|
|
254
|
+
name: t,
|
|
255
|
+
detail: n
|
|
256
|
+
}), this.batchDepth === 0 && this.flushLogs());
|
|
257
|
+
}
|
|
258
|
+
flushLogs() {
|
|
259
|
+
!this.loggerOptions?.isEnabled || this.pendingLogQueue.length === 0 || (this.pendingLogQueue = []);
|
|
344
260
|
}
|
|
345
|
-
resource(t, n
|
|
346
|
-
let
|
|
261
|
+
resource(e, t, n) {
|
|
262
|
+
let r = n && typeof n == "object" ? n.name : n || "unnamed_resource", i = this.signal({
|
|
347
263
|
data: null,
|
|
348
264
|
loading: !0,
|
|
349
265
|
error: null,
|
|
350
266
|
isRetrying: !1
|
|
351
|
-
}, `
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
});
|
|
358
|
-
}, _ = async (n, r, i = !1) => {
|
|
359
|
-
if (r.aborted) return;
|
|
360
|
-
if (l) {
|
|
361
|
-
let e = l(n);
|
|
362
|
-
if (e === !1 || typeof e == "string") {
|
|
363
|
-
if (r.aborted) return;
|
|
364
|
-
let t = typeof e == "string" ? e : "Pre-fetch validation failed for resource", n = i ? null : this.untrack(() => h.value.data);
|
|
365
|
-
g({
|
|
366
|
-
data: n,
|
|
367
|
-
loading: !1,
|
|
368
|
-
error: Error(t),
|
|
369
|
-
isRetrying: !1
|
|
370
|
-
});
|
|
371
|
-
return;
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
let o = i && s ? null : this.untrack(() => h.value.data);
|
|
375
|
-
g({
|
|
376
|
-
data: o,
|
|
377
|
-
loading: !0,
|
|
378
|
-
error: null,
|
|
379
|
-
isRetrying: !1
|
|
380
|
-
});
|
|
381
|
-
for (let i = 0; i <= u; i++) {
|
|
382
|
-
if (r.aborted) return;
|
|
383
|
-
let o = r;
|
|
384
|
-
try {
|
|
385
|
-
if (m && m > 0) {
|
|
386
|
-
let e = AbortSignal.timeout(m);
|
|
387
|
-
o = AbortSignal.any([r, e]);
|
|
388
|
-
}
|
|
389
|
-
let e = await t(n, o);
|
|
390
|
-
if (r.aborted) return;
|
|
391
|
-
if (o.aborted) throw new DOMException("The operation timed out.", "TimeoutError");
|
|
392
|
-
if (c) {
|
|
393
|
-
let t = c(e);
|
|
394
|
-
if (t === !1 || typeof t == "string") {
|
|
395
|
-
if (r.aborted) return;
|
|
396
|
-
g({
|
|
397
|
-
data: null,
|
|
398
|
-
loading: !1,
|
|
399
|
-
error: Error(typeof t == "string" ? t : "Validation failed"),
|
|
400
|
-
isRetrying: !1
|
|
401
|
-
});
|
|
402
|
-
return;
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
if (r.aborted) return;
|
|
406
|
-
g({
|
|
407
|
-
data: e,
|
|
408
|
-
loading: !1,
|
|
267
|
+
}, `resource:state:${r}`), a = this, o = null, s = async (t, n) => {
|
|
268
|
+
if (!n.aborted) {
|
|
269
|
+
a.untrack(() => {
|
|
270
|
+
i.value = {
|
|
271
|
+
data: i.value.data,
|
|
272
|
+
loading: !0,
|
|
409
273
|
error: null,
|
|
410
274
|
isRetrying: !1
|
|
275
|
+
};
|
|
276
|
+
});
|
|
277
|
+
try {
|
|
278
|
+
let r = await e(t, n);
|
|
279
|
+
n.aborted || a.untrack(() => {
|
|
280
|
+
i.value = {
|
|
281
|
+
data: r,
|
|
282
|
+
loading: !1,
|
|
283
|
+
error: null,
|
|
284
|
+
isRetrying: !1
|
|
285
|
+
};
|
|
411
286
|
});
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
let n = t.name === "TimeoutError" || t.name === "AbortError" || t.message?.includes("timeout"), o = e({
|
|
416
|
-
tested: [t.message],
|
|
417
|
-
expectedKey: "THROW_CUSTOM_VALIDATION_ERROR_NO_RETRY",
|
|
418
|
-
valueType: "number"
|
|
419
|
-
})?.[0] === "1" || !1, s = o && e({
|
|
420
|
-
tested: [t.message],
|
|
421
|
-
expectedKey: "MESSAGE",
|
|
422
|
-
valueType: "string"
|
|
423
|
-
})?.[0] || "Custom validation error", c = o || t.name === "ValidationError";
|
|
424
|
-
if (i === u || c) {
|
|
425
|
-
if (r.aborted) return;
|
|
426
|
-
let e = n ? Error(`Request timed out after ${m}ms`, { cause: t }) : o ? Error(s, { cause: t }) : t;
|
|
427
|
-
g({
|
|
287
|
+
} catch (e) {
|
|
288
|
+
n.aborted || a.untrack(() => {
|
|
289
|
+
i.value = {
|
|
428
290
|
data: null,
|
|
429
291
|
loading: !1,
|
|
430
292
|
error: e,
|
|
431
293
|
isRetrying: !1
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
} else {
|
|
435
|
-
if (r.aborted) return;
|
|
436
|
-
let e = f ? d * 2 ** i : d;
|
|
437
|
-
e = Math.min(e, p);
|
|
438
|
-
let t = Math.random() * 200;
|
|
439
|
-
e += t, g({
|
|
440
|
-
data: h.value.data,
|
|
441
|
-
loading: !0,
|
|
442
|
-
error: null,
|
|
443
|
-
isRetrying: !0
|
|
444
|
-
}), console.warn(`[Resource Retry] "${a}" сбой по ${n ? "таймауту" : "ошибке сети"}. Попытка ${i + 1}/${u + 1}...`);
|
|
445
|
-
try {
|
|
446
|
-
if (await this.delay(e, r), r.aborted) return;
|
|
447
|
-
} catch {
|
|
448
|
-
return;
|
|
449
|
-
}
|
|
450
|
-
}
|
|
294
|
+
};
|
|
295
|
+
});
|
|
451
296
|
}
|
|
452
297
|
}
|
|
453
|
-
}
|
|
298
|
+
};
|
|
454
299
|
return this.effect(() => {
|
|
455
|
-
let e =
|
|
456
|
-
return
|
|
457
|
-
|
|
458
|
-
}
|
|
459
|
-
}
|
|
300
|
+
let e = t ? t.value : void 0;
|
|
301
|
+
return o && o.abort(), o = new AbortController(), s(e, o.signal), () => {
|
|
302
|
+
o && o.abort();
|
|
303
|
+
};
|
|
304
|
+
}), {
|
|
460
305
|
get data() {
|
|
461
|
-
return
|
|
306
|
+
return i.value.data;
|
|
462
307
|
},
|
|
463
308
|
get loading() {
|
|
464
|
-
return
|
|
309
|
+
return i.value.loading;
|
|
465
310
|
},
|
|
466
311
|
get error() {
|
|
467
|
-
return
|
|
468
|
-
},
|
|
469
|
-
get isRetrying() {
|
|
470
|
-
return h.value.isRetrying;
|
|
312
|
+
return i.value.error;
|
|
471
313
|
},
|
|
472
314
|
get value() {
|
|
473
|
-
return
|
|
315
|
+
return i.value;
|
|
474
316
|
},
|
|
475
317
|
refetch: () => {
|
|
476
|
-
|
|
318
|
+
o && o.abort(), o = new AbortController(), s(t ? t.value : void 0, o.signal);
|
|
477
319
|
},
|
|
478
|
-
subscribe: (e) =>
|
|
320
|
+
subscribe: (e) => i.subscribe(e)
|
|
479
321
|
};
|
|
480
322
|
}
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
return e();
|
|
486
|
-
} finally {
|
|
487
|
-
this.activeEffect = t;
|
|
488
|
-
}
|
|
323
|
+
}, n = class extends t {
|
|
324
|
+
isFlushScheduled = !1;
|
|
325
|
+
constructor(e) {
|
|
326
|
+
super(e), this.frameworkPrefix = "auto-core";
|
|
489
327
|
}
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
328
|
+
reactive(e, t = "reactive") {
|
|
329
|
+
let n = this;
|
|
330
|
+
Reflect.has(e, "__subscribe") || Object.defineProperty(e, "__subscribe", {
|
|
331
|
+
get: () => (e) => {
|
|
332
|
+
let t = !1;
|
|
333
|
+
return n.effect(() => {
|
|
334
|
+
try {
|
|
335
|
+
JSON.stringify(r);
|
|
336
|
+
} catch {
|
|
337
|
+
Object.values(r);
|
|
338
|
+
}
|
|
339
|
+
t || (t = !0, queueMicrotask(() => {
|
|
340
|
+
t = !1, e();
|
|
341
|
+
}));
|
|
342
|
+
}, "auto-framework-proxy-internal-subscription");
|
|
343
|
+
},
|
|
344
|
+
configurable: !0,
|
|
345
|
+
enumerable: !1
|
|
346
|
+
});
|
|
347
|
+
let r = super.reactive(e, t);
|
|
348
|
+
return r;
|
|
349
|
+
}
|
|
350
|
+
flushEffects() {
|
|
351
|
+
this.batchDepth > 0 || this.isFlushScheduled || (this.isFlushScheduled = !0, queueMicrotask(() => {
|
|
352
|
+
this.isFlushScheduled = !1, super.flushEffects();
|
|
353
|
+
}));
|
|
354
|
+
}
|
|
355
|
+
effect(e, t) {
|
|
356
|
+
let n = this, r = {
|
|
357
|
+
id: ++n.subscriberId,
|
|
358
|
+
label: t,
|
|
359
|
+
cleanups: /* @__PURE__ */ new Set(),
|
|
360
|
+
markDirty() {
|
|
361
|
+
n.pendingEffects.add(r), n.flushEffects();
|
|
362
|
+
},
|
|
363
|
+
run() {
|
|
364
|
+
let t = Array.from(r.cleanups);
|
|
365
|
+
r.cleanups.clear(), t.forEach((e) => {
|
|
366
|
+
try {
|
|
367
|
+
e();
|
|
368
|
+
} catch (e) {
|
|
369
|
+
console.error("[Reactive Engine:Cleanup Error]", e);
|
|
370
|
+
}
|
|
371
|
+
});
|
|
372
|
+
let i = n.activeConsumer;
|
|
373
|
+
n.activeConsumer = r;
|
|
374
|
+
try {
|
|
375
|
+
let t = e();
|
|
376
|
+
typeof t == "function" && r.cleanups.add(t);
|
|
377
|
+
} finally {
|
|
378
|
+
n.activeConsumer = i;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
};
|
|
382
|
+
return n.allEffects.add(r), r.run(), () => {
|
|
383
|
+
Array.from(r.cleanups).forEach((e) => {
|
|
384
|
+
try {
|
|
385
|
+
e();
|
|
386
|
+
} catch (e) {
|
|
387
|
+
console.error("[Reactive Engine:Dispose Cleanup Error]", e);
|
|
388
|
+
}
|
|
389
|
+
}), r.cleanups.clear(), n.pendingEffects.delete(r), n.allEffects.delete(r);
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
}, r = class extends n {
|
|
393
|
+
autoLogQueue = [];
|
|
394
|
+
isHardFlushScheduled = !1;
|
|
395
|
+
constructor(e) {
|
|
396
|
+
let t = {
|
|
397
|
+
...e,
|
|
398
|
+
logger: {
|
|
399
|
+
isEnabled: !0,
|
|
400
|
+
traceTime: !0,
|
|
401
|
+
isCoreOptimizationDebugEnabled: !0,
|
|
402
|
+
instanceName: e?.logger?.instanceName || "AUTOMATIC_HARD_CORE",
|
|
403
|
+
filter: e?.logger?.filter
|
|
404
|
+
}
|
|
405
|
+
};
|
|
406
|
+
super(t), this.frameworkPrefix = "auto-hard-core";
|
|
407
|
+
}
|
|
408
|
+
queueLog(e, t, n) {
|
|
409
|
+
this.autoLogQueue.push({
|
|
410
|
+
type: e,
|
|
411
|
+
name: t,
|
|
412
|
+
detail: n
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
flushLogs() {
|
|
416
|
+
if (this.autoLogQueue.length === 0) return;
|
|
417
|
+
let e = {
|
|
418
|
+
signal: "background: #007acc; color: #fff; padding: 2px 6px; border-radius: 4px; font-weight: bold;",
|
|
419
|
+
computed: "background: #42b883; color: #fff; padding: 2px 6px; border-radius: 4px; font-weight: bold;",
|
|
420
|
+
effect: "background: #e01e5a; color: #fff; padding: 2px 6px; border-radius: 4px; font-weight: bold;",
|
|
421
|
+
batch: "background: #7952b3; color: #fff; padding: 2px 6px; border-radius: 4px; font-weight: bold;",
|
|
422
|
+
resource: "background: #d97706; color: #fff; padding: 2px 6px; border-radius: 4px; font-weight: bold;",
|
|
423
|
+
reactive: "background: #007acc; color: #fff; padding: 2px 6px; border-radius: 4px; font-weight: bold;"
|
|
424
|
+
};
|
|
425
|
+
console.groupCollapsed(`%cREACTIVE TRANSACTION [${this.frameworkPrefix.toUpperCase()}]%c Microtask Tick (Size: ${this.autoLogQueue.length})`, "background: #7952b3; color: #fff; padding: 2px 6px; border-radius: 4px; font-weight: bold;", "color: #aaa; font-weight: normal;"), this.autoLogQueue.forEach((t) => {
|
|
426
|
+
let n = "";
|
|
427
|
+
if (t.type === "signal") {
|
|
428
|
+
let e = t.detail;
|
|
429
|
+
n = ` 🔄 Изменение: [${String(e.from)} -> ${String(e.to)}]`;
|
|
430
|
+
} else if (t.type === "computed") n = ` 🧮 Расчет кэша (${t.detail.duration})`;
|
|
431
|
+
else if (t.type === "effect") {
|
|
432
|
+
let e = t.detail;
|
|
433
|
+
n = e?.isTriggered ? ` ⚡️ Ререндер/Вызов (${e.duration || "0ms"})` : " 🟢 Инициализация подписки";
|
|
434
|
+
} else if (t.type === "resource") {
|
|
435
|
+
let e = t.detail;
|
|
436
|
+
n = e.loading ? " ⏳ ЗАГРУЗКА СЕТИ" : e.error ? " 🔴 ОШИБКА" : " 🟢 УСПЕШНО ОТВЕТИЛ";
|
|
437
|
+
}
|
|
438
|
+
console.groupCollapsed(`%c${t.type.toUpperCase()}%c [${t.name}]%c${n}`, e[t.type] || e.signal, "color: #aaa; font-weight: bold;", "color: #42b883; font-weight: bold;"), console.log("Детали операции:", t.detail), console.groupEnd();
|
|
439
|
+
}), console.groupEnd(), this.autoLogQueue = [];
|
|
440
|
+
}
|
|
441
|
+
flushEffects() {
|
|
442
|
+
this.batchDepth > 0 || this.isHardFlushScheduled || (this.isHardFlushScheduled = !0, queueMicrotask(() => {
|
|
443
|
+
this.isHardFlushScheduled = !1, this.flushLogs(), super.flushEffects();
|
|
444
|
+
}));
|
|
445
|
+
}
|
|
446
|
+
effect(e, t) {
|
|
447
|
+
let n = this, r = t || "unnamed_effect", i = !0;
|
|
448
|
+
n.queueLog("effect", r, {
|
|
449
|
+
isTriggered: !1,
|
|
450
|
+
phase: "mount"
|
|
451
|
+
});
|
|
452
|
+
let a = {
|
|
453
|
+
id: ++n.subscriberId,
|
|
454
|
+
label: r,
|
|
455
|
+
cleanups: /* @__PURE__ */ new Set(),
|
|
456
|
+
markDirty() {
|
|
457
|
+
n.pendingEffects.add(a), n.flushEffects();
|
|
458
|
+
},
|
|
459
|
+
run() {
|
|
460
|
+
let t = typeof performance < "u" ? performance.now() : 0, o = Array.from(a.cleanups);
|
|
461
|
+
a.cleanups.clear(), o.forEach((e) => {
|
|
462
|
+
try {
|
|
463
|
+
e();
|
|
464
|
+
} catch (e) {
|
|
465
|
+
console.error("[Reactive Engine:Cleanup Error]", e);
|
|
466
|
+
}
|
|
467
|
+
});
|
|
468
|
+
let s = n.activeConsumer;
|
|
469
|
+
n.activeConsumer = a;
|
|
470
|
+
try {
|
|
471
|
+
let t = e();
|
|
472
|
+
typeof t == "function" && a.cleanups.add(t);
|
|
473
|
+
} finally {
|
|
474
|
+
if (n.activeConsumer = s, !i && t && typeof n.queueLog == "function") {
|
|
475
|
+
let e = performance.now() - t;
|
|
476
|
+
n.queueLog("effect", r, {
|
|
477
|
+
isTriggered: !0,
|
|
478
|
+
phase: "update",
|
|
479
|
+
duration: `${e.toFixed(3)}ms`
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
i = !1;
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
};
|
|
486
|
+
return n.allEffects.add(a), a.run(), () => {
|
|
487
|
+
Array.from(a.cleanups).forEach((e) => {
|
|
488
|
+
try {
|
|
489
|
+
e();
|
|
490
|
+
} catch (e) {
|
|
491
|
+
console.error("[Reactive Engine:Dispose Cleanup Error]", e);
|
|
492
|
+
}
|
|
493
|
+
}), a.cleanups.clear(), n.pendingEffects.delete(a), n.allEffects.delete(a), n.queueLog("effect", r, { phase: "unmount" });
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
resource(e, t, n) {
|
|
497
|
+
let r = n && typeof n == "object" ? n.name : n || "unnamed_resource", i = this;
|
|
498
|
+
return super.resource(async (t, n) => {
|
|
499
|
+
i.queueLog("resource", r, {
|
|
500
|
+
loading: !0,
|
|
501
|
+
error: null,
|
|
502
|
+
data: null
|
|
503
|
+
});
|
|
504
|
+
try {
|
|
505
|
+
let a = await e(t, n);
|
|
506
|
+
return i.queueLog("resource", r, {
|
|
507
|
+
loading: !1,
|
|
508
|
+
error: null,
|
|
509
|
+
data: a
|
|
510
|
+
}), a;
|
|
511
|
+
} catch (e) {
|
|
512
|
+
throw i.queueLog("resource", r, {
|
|
513
|
+
loading: !1,
|
|
514
|
+
error: e,
|
|
515
|
+
data: null
|
|
516
|
+
}), e;
|
|
517
|
+
}
|
|
518
|
+
}, t, n);
|
|
519
|
+
}
|
|
520
|
+
reactive(e, t = "reactive") {
|
|
521
|
+
let n = this, r = super.reactive(e, t);
|
|
522
|
+
return new Proxy(r, {
|
|
523
|
+
get(e, r, i) {
|
|
524
|
+
let a = Reflect.get(e, r, i);
|
|
525
|
+
return typeof a == "object" && a ? n.reactive(a, `${t}.${String(r)}`) : a;
|
|
526
|
+
},
|
|
527
|
+
set(e, r, i, a) {
|
|
528
|
+
let o = Reflect.get(e, r, a);
|
|
529
|
+
return o === i ? !0 : (n.queueLog("signal", `${t}.${String(r)}`, {
|
|
530
|
+
from: o,
|
|
531
|
+
to: i,
|
|
532
|
+
subscribersCount: 0,
|
|
533
|
+
subscribers: ["framework-reactive-proxy-subscriber"]
|
|
534
|
+
}), Reflect.set(e, r, i, a));
|
|
535
|
+
}
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
signal(e, t) {
|
|
539
|
+
let n = this, r = (typeof t == "string" ? { name: t } : t || {}).name || "unnamed_signal", i = super.signal(e, t);
|
|
540
|
+
return {
|
|
541
|
+
get value() {
|
|
542
|
+
return i.value;
|
|
543
|
+
},
|
|
544
|
+
set value(e) {
|
|
545
|
+
let t = i.value;
|
|
546
|
+
if ((e === null || typeof e != "object" && typeof e != "function") && t === e) return;
|
|
547
|
+
let a = n.activeConsumer, o = a && "label" in a && typeof a.label == "string" ? a.label : "unnamed_effect";
|
|
548
|
+
n.queueLog("signal", r, {
|
|
549
|
+
from: t,
|
|
550
|
+
to: e,
|
|
551
|
+
subscribersCount: 0,
|
|
552
|
+
subscribers: [o]
|
|
553
|
+
}), i.value = e;
|
|
554
|
+
},
|
|
555
|
+
subscribe(e) {
|
|
556
|
+
return i.subscribe(e);
|
|
557
|
+
}
|
|
558
|
+
};
|
|
559
|
+
}
|
|
560
|
+
computed(e, t) {
|
|
561
|
+
let n = this, r = t || "unnamed_computed", i = super.computed(e, t);
|
|
562
|
+
return {
|
|
563
|
+
get value() {
|
|
564
|
+
let e = typeof performance < "u" ? performance.now() : 0, t = i.value;
|
|
565
|
+
if (e) {
|
|
566
|
+
let i = performance.now() - e;
|
|
567
|
+
n.queueLog("computed", r, {
|
|
568
|
+
value: t,
|
|
569
|
+
duration: `${i.toFixed(3)}ms`
|
|
570
|
+
});
|
|
571
|
+
}
|
|
572
|
+
return t;
|
|
573
|
+
},
|
|
574
|
+
subscribe: (e) => i.subscribe(e),
|
|
575
|
+
destroy() {
|
|
576
|
+
i.destroy();
|
|
577
|
+
}
|
|
578
|
+
};
|
|
496
579
|
}
|
|
497
580
|
};
|
|
498
581
|
//#endregion
|
|
499
|
-
export { t as ReactiveEngine };
|
|
582
|
+
export { t as ReactiveEngine, n as ReactiveEngineAutomatic, r as ReactiveEngineAutomaticHard, e as ReactiveEngineCore };
|
|
500
583
|
|
|
501
584
|
//# sourceMappingURL=core.mjs.map
|