@pravosleva/reactive-engine 0.4.1-beta → 1.0.1-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/README.md +33 -2
- package/dist/AbstractService.cjs +2 -0
- package/dist/AbstractService.cjs.map +1 -0
- package/dist/AbstractService.mjs +24 -0
- package/dist/AbstractService.mjs.map +1 -0
- package/dist/BaseREServiceEnhanced.cjs +2 -0
- package/dist/BaseREServiceEnhanced.cjs.map +1 -0
- package/dist/BaseREServiceEnhanced.mjs +12 -0
- package/dist/BaseREServiceEnhanced.mjs.map +1 -0
- package/dist/_react-bindings.d.ts +17 -0
- package/dist/_react-bindings.d.ts.map +1 -0
- package/dist/_virtual/_rolldown/runtime.cjs +1 -0
- package/dist/core/AbstractService.d.ts +11 -0
- package/dist/core/AbstractService.d.ts.map +1 -0
- package/dist/core/BaseREServiceEnhanced.d.ts +7 -0
- package/dist/core/BaseREServiceEnhanced.d.ts.map +1 -0
- package/dist/core/core.d.ts +282 -0
- package/dist/core/core.d.ts.map +1 -0
- package/dist/core/core.test.d.ts +2 -0
- package/dist/core/core.test.d.ts.map +1 -0
- package/dist/core/index.d.ts +5 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/types.d.ts +92 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core.cjs +2 -0
- package/dist/core.cjs.map +1 -0
- package/dist/core.mjs +286 -0
- package/dist/core.mjs.map +1 -0
- package/dist/decorators/index.d.ts +6 -0
- package/dist/decorators/index.d.ts.map +1 -0
- package/dist/decorators/withCache/index.d.ts +2 -0
- package/dist/decorators/withCache/index.d.ts.map +1 -0
- package/dist/decorators/withCache/withCache.d.ts +13 -0
- package/dist/decorators/withCache/withCache.d.ts.map +1 -0
- package/dist/decorators/withCache/withCache.test.d.ts +2 -0
- package/dist/decorators/withCache/withCache.test.d.ts.map +1 -0
- package/dist/decorators/withDebounce/index.d.ts +2 -0
- package/dist/decorators/withDebounce/index.d.ts.map +1 -0
- package/dist/decorators/withDebounce/withDebounce.d.ts +12 -0
- package/dist/decorators/withDebounce/withDebounce.d.ts.map +1 -0
- package/dist/decorators/withDebounce/withDebounce.test.d.ts +2 -0
- package/dist/decorators/withDebounce/withDebounce.test.d.ts.map +1 -0
- package/dist/decorators/withLongPolling/index.d.ts +2 -0
- package/dist/decorators/withLongPolling/index.d.ts.map +1 -0
- package/dist/decorators/withLongPolling/withLongPolling.d.ts +28 -0
- package/dist/decorators/withLongPolling/withLongPolling.d.ts.map +1 -0
- package/dist/decorators/withLongPolling/withLongPolling.test.d.ts +2 -0
- package/dist/decorators/withLongPolling/withLongPolling.test.d.ts.map +1 -0
- package/dist/decorators/withThrottle/index.d.ts +2 -0
- package/dist/decorators/withThrottle/index.d.ts.map +1 -0
- package/dist/decorators/withThrottle/withThrottle.d.ts +12 -0
- package/dist/decorators/withThrottle/withThrottle.d.ts.map +1 -0
- package/dist/decorators/withThrottle/withThrottle.test.d.ts +2 -0
- package/dist/decorators/withThrottle/withThrottle.test.d.ts.map +1 -0
- package/dist/decorators/withThrottleAndCache/index.d.ts +2 -0
- package/dist/decorators/withThrottleAndCache/index.d.ts.map +1 -0
- package/dist/decorators/withThrottleAndCache/withThrottleAndCache.d.ts +13 -0
- package/dist/decorators/withThrottleAndCache/withThrottleAndCache.d.ts.map +1 -0
- package/dist/decorators/withThrottleAndCache/withThrottleAndCache.test.d.ts +2 -0
- package/dist/decorators/withThrottleAndCache/withThrottleAndCache.test.d.ts.map +1 -0
- package/dist/index.cjs +1 -6
- package/dist/index.d.ts +2 -605
- package/dist/index.d.ts.map +1 -0
- package/dist/index.mjs +4 -541
- package/dist/react/ReactiveEngine4React.cjs +6 -0
- package/dist/react/ReactiveEngine4React.cjs.map +1 -0
- package/dist/react/ReactiveEngine4React.d.ts +27 -0
- package/dist/react/ReactiveEngine4React.d.ts.map +1 -0
- package/dist/react/ReactiveEngine4React.mjs +28 -0
- package/dist/react/ReactiveEngine4React.mjs.map +1 -0
- package/dist/react/core.react.test.d.ts +2 -0
- package/dist/react/core.react.test.d.ts.map +1 -0
- package/dist/react/createObserver.cjs +2 -0
- package/dist/react/createObserver.cjs.map +1 -0
- package/dist/react/createObserver.d.ts +70 -0
- package/dist/react/createObserver.d.ts.map +1 -0
- package/dist/react/createObserver.mjs +62 -0
- package/dist/react/createObserver.mjs.map +1 -0
- package/dist/react/createObserver.test.d.ts +2 -0
- package/dist/react/createObserver.test.d.ts.map +1 -0
- package/dist/react/hooks/FilteredCatalog.test.d.ts +2 -0
- package/dist/react/hooks/FilteredCatalog.test.d.ts.map +1 -0
- package/dist/react/hooks/index.cjs +1 -0
- package/dist/react/hooks/index.d.ts +4 -0
- package/dist/react/hooks/index.d.ts.map +1 -0
- package/dist/react/hooks/index.mjs +7 -0
- package/dist/react/hooks/types.d.ts +16 -0
- package/dist/react/hooks/types.d.ts.map +1 -0
- package/dist/react/hooks/useReactiveSubscription/index.cjs +1 -0
- package/dist/react/hooks/useReactiveSubscription/index.d.ts +2 -0
- package/dist/react/hooks/useReactiveSubscription/index.d.ts.map +1 -0
- package/dist/react/hooks/useReactiveSubscription/index.mjs +2 -0
- package/dist/react/hooks/useReactiveSubscription/useReactiveSubscription.cjs +2 -0
- package/dist/react/hooks/useReactiveSubscription/useReactiveSubscription.cjs.map +1 -0
- package/dist/react/hooks/useReactiveSubscription/useReactiveSubscription.d.ts +10 -0
- package/dist/react/hooks/useReactiveSubscription/useReactiveSubscription.d.ts.map +1 -0
- package/dist/react/hooks/useReactiveSubscription/useReactiveSubscription.mjs +14 -0
- package/dist/react/hooks/useReactiveSubscription/useReactiveSubscription.mjs.map +1 -0
- package/dist/react/hooks/useReactiveSubscription/useReactiveSubscription.test.d.ts +2 -0
- package/dist/react/hooks/useReactiveSubscription/useReactiveSubscription.test.d.ts.map +1 -0
- package/dist/react/hooks/useReactiveValue/index.cjs +1 -0
- package/dist/react/hooks/useReactiveValue/index.d.ts +2 -0
- package/dist/react/hooks/useReactiveValue/index.d.ts.map +1 -0
- package/dist/react/hooks/useReactiveValue/index.mjs +2 -0
- package/dist/react/hooks/useReactiveValue/useReactiveValue.cjs +2 -0
- package/dist/react/hooks/useReactiveValue/useReactiveValue.cjs.map +1 -0
- package/dist/react/hooks/useReactiveValue/useReactiveValue.d.ts +16 -0
- package/dist/react/hooks/useReactiveValue/useReactiveValue.d.ts.map +1 -0
- package/dist/react/hooks/useReactiveValue/useReactiveValue.mjs +12 -0
- package/dist/react/hooks/useReactiveValue/useReactiveValue.mjs.map +1 -0
- package/dist/react/hooks/useReactiveValue/useReactiveValue.test.d.ts +2 -0
- package/dist/react/hooks/useReactiveValue/useReactiveValue.test.d.ts.map +1 -0
- package/dist/react/hooks/useReactiveValue0/index.cjs +1 -0
- package/dist/react/hooks/useReactiveValue0/index.d.ts +2 -0
- package/dist/react/hooks/useReactiveValue0/index.d.ts.map +1 -0
- package/dist/react/hooks/useReactiveValue0/index.mjs +2 -0
- package/dist/react/hooks/useReactiveValue0/useReactiveValue0.cjs +2 -0
- package/dist/react/hooks/useReactiveValue0/useReactiveValue0.cjs.map +1 -0
- package/dist/react/hooks/useReactiveValue0/useReactiveValue0.d.ts +15 -0
- package/dist/react/hooks/useReactiveValue0/useReactiveValue0.d.ts.map +1 -0
- package/dist/react/hooks/useReactiveValue0/useReactiveValue0.mjs +20 -0
- package/dist/react/hooks/useReactiveValue0/useReactiveValue0.mjs.map +1 -0
- package/dist/react/index.cjs +1 -0
- package/dist/react/index.d.ts +4 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.mjs +7 -0
- package/dist/react/types.d.ts +2 -0
- package/dist/react/types.d.ts.map +1 -0
- package/dist/utils/getExtractedValues.cjs +2 -0
- package/dist/utils/getExtractedValues.cjs.map +1 -0
- package/dist/utils/getExtractedValues.d.ts +6 -0
- package/dist/utils/getExtractedValues.d.ts.map +1 -0
- package/dist/utils/getExtractedValues.mjs +21 -0
- package/dist/utils/getExtractedValues.mjs.map +1 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/package.json +25 -4
- package/dist/index.cjs.map +0 -1
- package/dist/index.iife.js +0 -6
- package/dist/index.iife.js.map +0 -1
- package/dist/index.mjs.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,541 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
constructor(e) {
|
|
6
|
-
this.engine = e, this.onInit();
|
|
7
|
-
}
|
|
8
|
-
createNumericSignal(e, t) {
|
|
9
|
-
return this.engine.signal(e, {
|
|
10
|
-
name: t,
|
|
11
|
-
validate: (e) => typeof e == "number" && !isNaN(e)
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
createComputed(e) {
|
|
15
|
-
return this.engine.computed(e);
|
|
16
|
-
}
|
|
17
|
-
createSignal(e, t) {
|
|
18
|
-
return this.engine.signal(e, t);
|
|
19
|
-
}
|
|
20
|
-
onInit() {}
|
|
21
|
-
}, c = s, l = class {
|
|
22
|
-
engine;
|
|
23
|
-
constructor(e) {
|
|
24
|
-
this.engine = e, setTimeout(() => this.onInit(), 0);
|
|
25
|
-
}
|
|
26
|
-
onInit() {}
|
|
27
|
-
}, u = ({ tested: e, expectedKey: t, valueType: n }) => {
|
|
28
|
-
let r = [];
|
|
29
|
-
for (let i = 0, a = e.length; i < a; i++) {
|
|
30
|
-
let a = e[i], o;
|
|
31
|
-
switch (n) {
|
|
32
|
-
case "number":
|
|
33
|
-
o = RegExp(`\\[${t}=(?<value>\\d+)\\]`, "g");
|
|
34
|
-
break;
|
|
35
|
-
default:
|
|
36
|
-
o = RegExp(`\\[${t}=(?<value>.*?)\\]`, "g");
|
|
37
|
-
break;
|
|
38
|
-
}
|
|
39
|
-
for (let e of a.matchAll(o)) e?.groups && r.push(e.groups.value);
|
|
40
|
-
}
|
|
41
|
-
return r;
|
|
42
|
-
}, d = class {
|
|
43
|
-
activeEffect = null;
|
|
44
|
-
isBatching = !1;
|
|
45
|
-
pendingEffects = /* @__PURE__ */ new Set();
|
|
46
|
-
services = /* @__PURE__ */ new Map();
|
|
47
|
-
factories = /* @__PURE__ */ new Map();
|
|
48
|
-
proxyCache = /* @__PURE__ */ new WeakMap();
|
|
49
|
-
allEffects = /* @__PURE__ */ new Set();
|
|
50
|
-
onSignalChange;
|
|
51
|
-
reactAdapters = {
|
|
52
|
-
useState: a,
|
|
53
|
-
useEffect: n
|
|
54
|
-
};
|
|
55
|
-
provide(e, t) {
|
|
56
|
-
typeof t == "function" && !t.prototype ? this.factories.set(e, t) : this.services.set(e, t);
|
|
57
|
-
}
|
|
58
|
-
inject(e) {
|
|
59
|
-
if (!e) throw Error("[DI Error]: Вы пытаетесь внедрить пустой токен (undefined/null). Проверьте импорты.");
|
|
60
|
-
let t = e;
|
|
61
|
-
if (this.services.has(t)) return this.services.get(t);
|
|
62
|
-
try {
|
|
63
|
-
let n = this.factories.get(t);
|
|
64
|
-
if (n) {
|
|
65
|
-
let e = n(this);
|
|
66
|
-
return this.services.set(t, e), e;
|
|
67
|
-
}
|
|
68
|
-
if (typeof e == "function" && e.prototype) {
|
|
69
|
-
let n = new e(this);
|
|
70
|
-
return this.services.set(t, n), n;
|
|
71
|
-
}
|
|
72
|
-
throw Error(`Service not found: ${String(e)}`);
|
|
73
|
-
} catch (t) {
|
|
74
|
-
throw Error(`[DI Error]: Не удалось создать сервис ${String(e)}. Ошибка: ${t?.message || "No e?.message"}`);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
signal(e, t) {
|
|
78
|
-
let n = this, r = e, i = /* @__PURE__ */ new Set(), a = typeof t == "string" ? { name: t } : t || {}, o = a.name || "unnamed_signal";
|
|
79
|
-
return {
|
|
80
|
-
get value() {
|
|
81
|
-
return n.activeEffect && i.add(n.activeEffect), r;
|
|
82
|
-
},
|
|
83
|
-
set value(e) {
|
|
84
|
-
if (r === e) return;
|
|
85
|
-
if (a.validate) {
|
|
86
|
-
let t = a.validate(e);
|
|
87
|
-
if (t === !1 || typeof t == "string") {
|
|
88
|
-
let n = typeof t == "string" ? t : `[Validation Error]: Некорректное значение для сигнала "${o}"`;
|
|
89
|
-
console.error(`%c${n}`, "color: orange; font-weight: bold;", {
|
|
90
|
-
received: e,
|
|
91
|
-
current: r
|
|
92
|
-
});
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
let t = r;
|
|
97
|
-
r = e, n.onSignalChange?.(o, e, t), i.forEach((e) => n.pendingEffects.add(e)), n.isBatching || (n.isBatching = !0, queueMicrotask(() => {
|
|
98
|
-
let e = Array.from(n.pendingEffects);
|
|
99
|
-
n.pendingEffects.clear(), n.isBatching = !1, e.forEach((e) => e.run());
|
|
100
|
-
}));
|
|
101
|
-
},
|
|
102
|
-
subscribe(e) {
|
|
103
|
-
return n.effect(() => {
|
|
104
|
-
e(this.value);
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
effect(e, t) {
|
|
110
|
-
let n = this, r = {
|
|
111
|
-
label: t,
|
|
112
|
-
cleanups: /* @__PURE__ */ new Set(),
|
|
113
|
-
run() {
|
|
114
|
-
this.cleanups.forEach((e) => e()), this.cleanups.clear();
|
|
115
|
-
let t = n.activeEffect;
|
|
116
|
-
n.activeEffect = this, n.safeRun(this, () => {
|
|
117
|
-
let t = e();
|
|
118
|
-
typeof t == "function" && this.cleanups.add(t);
|
|
119
|
-
}), n.activeEffect = t;
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
return this.allEffects.add(r), r.run(), () => {
|
|
123
|
-
r.cleanups.forEach((e) => e()), n.pendingEffects.delete(r), n.allEffects.delete(r);
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
computedCache = /* @__PURE__ */ new Map();
|
|
127
|
-
cleanupRegistry = new FinalizationRegistry((e) => {
|
|
128
|
-
e();
|
|
129
|
-
});
|
|
130
|
-
computed(e, t) {
|
|
131
|
-
if (this.computedCache.has(e)) {
|
|
132
|
-
let t = this.computedCache.get(e)?.deref();
|
|
133
|
-
if (t) return t;
|
|
134
|
-
}
|
|
135
|
-
let n = this, r = this.signal(void 0, t || "unnamed_computed"), i = this.effect(() => {
|
|
136
|
-
let t = e();
|
|
137
|
-
r.value = t;
|
|
138
|
-
}), a = Array.from(this.allEffects)[this.allEffects.size - 1], o = () => {
|
|
139
|
-
i(), a && n.allEffects.delete(a), n.computedCache.delete(e);
|
|
140
|
-
}, s = {
|
|
141
|
-
get value() {
|
|
142
|
-
return r.value;
|
|
143
|
-
},
|
|
144
|
-
subscribe: (e) => r.subscribe(e),
|
|
145
|
-
destroy() {
|
|
146
|
-
o();
|
|
147
|
-
}
|
|
148
|
-
};
|
|
149
|
-
return this.cleanupRegistry.register(s, o), this.computedCache.set(e, new WeakRef(s)), s;
|
|
150
|
-
}
|
|
151
|
-
reactive(e, t = "reactive") {
|
|
152
|
-
if (this.proxyCache.has(e)) return this.proxyCache.get(e);
|
|
153
|
-
let n = this, r = /* @__PURE__ */ new Map(), i = new Proxy(e, {
|
|
154
|
-
get(e, i, a) {
|
|
155
|
-
n.activeEffect && (r.has(i) || r.set(i, /* @__PURE__ */ new Set()), r.get(i).add(n.activeEffect));
|
|
156
|
-
let o = Reflect.get(e, i, a);
|
|
157
|
-
return typeof o == "object" && o ? n.reactive(o, `${t}.${String(i)}`) : o;
|
|
158
|
-
},
|
|
159
|
-
set(e, i, a, o) {
|
|
160
|
-
let s = Reflect.get(e, i, o);
|
|
161
|
-
return s === a || s !== a && (Reflect.set(e, i, a, o), n.onSignalChange?.(`${t}.${String(i)}`, a, s), r.get(i)?.forEach((e) => n.isBatching ? n.pendingEffects.add(e) : e.run())), !0;
|
|
162
|
-
}
|
|
163
|
-
});
|
|
164
|
-
return this.proxyCache.set(e, i), i;
|
|
165
|
-
}
|
|
166
|
-
batch(e) {
|
|
167
|
-
e();
|
|
168
|
-
}
|
|
169
|
-
delay(e, t) {
|
|
170
|
-
return new Promise((n, r) => {
|
|
171
|
-
if (t.aborted) return r(new DOMException("Aborted", "AbortError"));
|
|
172
|
-
let i = setTimeout(() => {
|
|
173
|
-
t.removeEventListener("abort", a), n();
|
|
174
|
-
}, e), a = () => {
|
|
175
|
-
clearTimeout(i), r(new DOMException("Aborted", "AbortError"));
|
|
176
|
-
};
|
|
177
|
-
t.addEventListener("abort", a, { once: !0 });
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
resource(e, t, n) {
|
|
181
|
-
let r = n && typeof n == "object", i = r ? n.name : n || "unnamed_resource", a = r ? n : {}, o = a.resetDataOnSourceChange ?? !0, s = a.responseValidate, c = a.validateBeforeFetch, l = a.retryCount ?? 0, d = a.retryDelay ?? 1e3, f = a.isExponentialBackoffEnabled ?? !1, p = a.maxRetryDelay ?? 3e4, m = a.timeout, h = this.signal({
|
|
182
|
-
data: null,
|
|
183
|
-
loading: !0,
|
|
184
|
-
error: null,
|
|
185
|
-
isRetrying: !1
|
|
186
|
-
}, i), g = async (t, n, r = !1) => {
|
|
187
|
-
if (n.aborted) return;
|
|
188
|
-
if (c) {
|
|
189
|
-
let e = c(t);
|
|
190
|
-
if (e === !1 || typeof e == "string") {
|
|
191
|
-
if (n.aborted) return;
|
|
192
|
-
let t = typeof e == "string" ? e : "Pre-fetch validation failed for resource", i = r ? null : this.untrack(() => h.value.data);
|
|
193
|
-
h.value = {
|
|
194
|
-
data: i,
|
|
195
|
-
loading: !1,
|
|
196
|
-
error: Error(t),
|
|
197
|
-
isRetrying: !1
|
|
198
|
-
};
|
|
199
|
-
return;
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
let a = r && o ? null : this.untrack(() => h.value.data);
|
|
203
|
-
h.value = {
|
|
204
|
-
data: a,
|
|
205
|
-
loading: !0,
|
|
206
|
-
error: null,
|
|
207
|
-
isRetrying: !1
|
|
208
|
-
};
|
|
209
|
-
for (let r = 0; r <= l; r++) {
|
|
210
|
-
if (n.aborted) return;
|
|
211
|
-
let a = n;
|
|
212
|
-
try {
|
|
213
|
-
if (m && m > 0) {
|
|
214
|
-
let e = AbortSignal.timeout(m);
|
|
215
|
-
a = AbortSignal.any([n, e]);
|
|
216
|
-
}
|
|
217
|
-
let r = await e(t, a);
|
|
218
|
-
if (n.aborted) return;
|
|
219
|
-
if (a.aborted) throw new DOMException("The operation timed out.", "TimeoutError");
|
|
220
|
-
if (s) {
|
|
221
|
-
let e = s(r);
|
|
222
|
-
if (e === !1 || typeof e == "string") {
|
|
223
|
-
if (n.aborted) return;
|
|
224
|
-
h.value = {
|
|
225
|
-
data: null,
|
|
226
|
-
loading: !1,
|
|
227
|
-
error: Error(typeof e == "string" ? e : "Validation failed"),
|
|
228
|
-
isRetrying: !1
|
|
229
|
-
};
|
|
230
|
-
return;
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
if (n.aborted) return;
|
|
234
|
-
h.value = {
|
|
235
|
-
data: r,
|
|
236
|
-
loading: !1,
|
|
237
|
-
error: null,
|
|
238
|
-
isRetrying: !1
|
|
239
|
-
};
|
|
240
|
-
return;
|
|
241
|
-
} catch (e) {
|
|
242
|
-
if (n.aborted || e.name === "AbortError" && n.aborted) return;
|
|
243
|
-
let t = e.name === "TimeoutError" || e.name === "AbortError" || e.message?.includes("timeout"), a = u({
|
|
244
|
-
tested: [e.message],
|
|
245
|
-
expectedKey: "THROW_CUSTOM_VALIDATION_ERROR_NO_RETRY",
|
|
246
|
-
valueType: "number"
|
|
247
|
-
})?.[0] === "1" || !1, o = a && u({
|
|
248
|
-
tested: [e.message],
|
|
249
|
-
expectedKey: "MESSAGE",
|
|
250
|
-
valueType: "string"
|
|
251
|
-
})?.[0] || "Custom validation error", s = a || e.name === "ValidationError";
|
|
252
|
-
if (r === l || s) {
|
|
253
|
-
if (n.aborted) return;
|
|
254
|
-
let r = t ? Error(`Request timed out after ${m}ms`, { cause: e }) : a ? Error(o, { cause: e }) : e;
|
|
255
|
-
h.value = {
|
|
256
|
-
data: null,
|
|
257
|
-
loading: !1,
|
|
258
|
-
error: r,
|
|
259
|
-
isRetrying: !1
|
|
260
|
-
};
|
|
261
|
-
return;
|
|
262
|
-
} else {
|
|
263
|
-
if (n.aborted) return;
|
|
264
|
-
let e = f ? d * 2 ** r : d;
|
|
265
|
-
e = Math.min(e, p);
|
|
266
|
-
let a = Math.random() * 200;
|
|
267
|
-
e += a, h.value = {
|
|
268
|
-
data: h.value.data,
|
|
269
|
-
loading: !0,
|
|
270
|
-
error: null,
|
|
271
|
-
isRetrying: !0
|
|
272
|
-
}, console.warn(`[Resource Retry] "${i}" сбой по ${t ? "таймауту" : "ошибке сети"}. Попытка ${r + 1}/${l + 1}...`);
|
|
273
|
-
try {
|
|
274
|
-
if (await this.delay(e, n), n.aborted) return;
|
|
275
|
-
} catch {
|
|
276
|
-
return;
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
}, _ = null;
|
|
282
|
-
return this.effect(() => {
|
|
283
|
-
let e = t ? t.value : void 0, n = new AbortController();
|
|
284
|
-
return _ = n, this.untrack(() => {
|
|
285
|
-
g(e, n.signal, !0);
|
|
286
|
-
}), () => n.abort();
|
|
287
|
-
}), {
|
|
288
|
-
get data() {
|
|
289
|
-
return h.value.data;
|
|
290
|
-
},
|
|
291
|
-
get loading() {
|
|
292
|
-
return h.value.loading;
|
|
293
|
-
},
|
|
294
|
-
get error() {
|
|
295
|
-
return h.value.error;
|
|
296
|
-
},
|
|
297
|
-
get isRetrying() {
|
|
298
|
-
return h.value.isRetrying;
|
|
299
|
-
},
|
|
300
|
-
get value() {
|
|
301
|
-
return h.value;
|
|
302
|
-
},
|
|
303
|
-
refetch: () => {
|
|
304
|
-
_?.abort(), _ = new AbortController(), g(t ? t.value : void 0, _.signal, !1);
|
|
305
|
-
},
|
|
306
|
-
subscribe: (e) => h.subscribe(e)
|
|
307
|
-
};
|
|
308
|
-
}
|
|
309
|
-
untrack(e) {
|
|
310
|
-
let t = this.activeEffect;
|
|
311
|
-
this.activeEffect = null;
|
|
312
|
-
try {
|
|
313
|
-
return e();
|
|
314
|
-
} finally {
|
|
315
|
-
this.activeEffect = t;
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
setReactAdapters(e, t) {
|
|
319
|
-
this.reactAdapters = {
|
|
320
|
-
useState: e,
|
|
321
|
-
useEffect: t
|
|
322
|
-
};
|
|
323
|
-
}
|
|
324
|
-
use(e) {
|
|
325
|
-
if (!this.reactAdapters) throw Error("[React Error]: Адаптеры React не установлены. Вызовите engine.setReactAdapters(useState, useEffect).");
|
|
326
|
-
if (!e || typeof e.subscribe != "function") {
|
|
327
|
-
let t = "\n [Reactive Error]: engine.use() получил некорректный объект!\n Скорее всего, вы пытаетесь подписаться на свойство сервиса, которое не было инициализировано.\n Проверьте, что в классе написано: public mySignal = this.engine.signal(...)\n ";
|
|
328
|
-
throw console.error(t, { item: e }), Error(t);
|
|
329
|
-
}
|
|
330
|
-
let [t, n] = this.reactAdapters.useState(e.value);
|
|
331
|
-
return this.reactAdapters.useEffect(() => e.subscribe(n), [e]), t;
|
|
332
|
-
}
|
|
333
|
-
safeRun(e, t) {
|
|
334
|
-
try {
|
|
335
|
-
t();
|
|
336
|
-
} catch (e) {
|
|
337
|
-
console.error("%c[Reactive Error] %cОшибка в эффекте/computed:", "color: white; background: red; padding: 2px 4px; border-radius: 3px;", "font-weight: bold;", e);
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
}, f = (e) => ({ children: t }) => {
|
|
341
|
-
let a = i(0), s = i(null), c = i(null), l = i(null), u = r(() => ({
|
|
342
|
-
subscribe(e) {
|
|
343
|
-
return s.current = e, () => {
|
|
344
|
-
s.current = null, c.current && (c.current(), c.current = null, l.current = null);
|
|
345
|
-
};
|
|
346
|
-
},
|
|
347
|
-
getSnapshot() {
|
|
348
|
-
return a.current;
|
|
349
|
-
}
|
|
350
|
-
}), []);
|
|
351
|
-
n(() => () => {
|
|
352
|
-
c.current && c.current();
|
|
353
|
-
}, []), c.current || (c.current = e.effect(() => {
|
|
354
|
-
s.current && (a.current++, queueMicrotask(() => {
|
|
355
|
-
s.current && s.current();
|
|
356
|
-
}));
|
|
357
|
-
}), l.current = Array.from(e.allEffects).pop());
|
|
358
|
-
let d = e.activeEffect;
|
|
359
|
-
e.activeEffect = l.current;
|
|
360
|
-
let f = null;
|
|
361
|
-
try {
|
|
362
|
-
f = t();
|
|
363
|
-
} finally {
|
|
364
|
-
e.activeEffect = d;
|
|
365
|
-
}
|
|
366
|
-
return o(u.subscribe, u.getSnapshot), f;
|
|
367
|
-
}, p = (t) => (n) => {
|
|
368
|
-
let a = (a) => {
|
|
369
|
-
let s = i(0), c = t, l = "activeEffect" in c ? "activeEffect" : "_activeEffect", u = i(null), { subscribe: d, getSnapshot: f } = r(() => ({
|
|
370
|
-
subscribe: (e) => {
|
|
371
|
-
let n = t.effect(() => {
|
|
372
|
-
s.current++, e();
|
|
373
|
-
}), r = Array.from(c.allEffects || []);
|
|
374
|
-
return u.current = r[r.length - 1], () => {
|
|
375
|
-
n(), u.current = null;
|
|
376
|
-
};
|
|
377
|
-
},
|
|
378
|
-
getSnapshot: () => s.current
|
|
379
|
-
}), []);
|
|
380
|
-
o(d, f, f);
|
|
381
|
-
let p = {
|
|
382
|
-
cleanups: /* @__PURE__ */ new Set(),
|
|
383
|
-
run: () => {}
|
|
384
|
-
}, m = u.current || p, h = c[l];
|
|
385
|
-
c[l] = m;
|
|
386
|
-
let g = null;
|
|
387
|
-
try {
|
|
388
|
-
g = typeof n == "function" && !n.prototype?.isReactComponent ? n(a) : e.createElement(n, a);
|
|
389
|
-
} finally {
|
|
390
|
-
c[l] = h;
|
|
391
|
-
}
|
|
392
|
-
return g;
|
|
393
|
-
};
|
|
394
|
-
return a.displayName = `Observer(${n.displayName || n.name || "Component"})`, a;
|
|
395
|
-
}, m = (e, t = {}) => {
|
|
396
|
-
let n = t.ttl ?? 300 * 1e3, r = /* @__PURE__ */ new Map();
|
|
397
|
-
return async (t, i) => {
|
|
398
|
-
let a = typeof t == "object" && t ? JSON.stringify(t) : String(t), o = Date.now(), s = r.get(a);
|
|
399
|
-
if (s && o - s.timestamp < n) return s.data;
|
|
400
|
-
let c = await e(t, i);
|
|
401
|
-
return r.set(a, {
|
|
402
|
-
data: c,
|
|
403
|
-
timestamp: Date.now()
|
|
404
|
-
}), c;
|
|
405
|
-
};
|
|
406
|
-
}, h = (e, t = {}) => {
|
|
407
|
-
let n = t.delay ?? 300, r = null, i = null;
|
|
408
|
-
return (t, a) => (r && clearTimeout(r), i && i(new DOMException("Aborted due to debounce", "AbortError")), new Promise((o, s) => {
|
|
409
|
-
i = s;
|
|
410
|
-
let c = () => {
|
|
411
|
-
r && clearTimeout(r), s(new DOMException("Aborted by resource signal", "AbortError"));
|
|
412
|
-
};
|
|
413
|
-
if (a.aborted) return c();
|
|
414
|
-
a.addEventListener("abort", c), r = setTimeout(async () => {
|
|
415
|
-
a.removeEventListener("abort", c), i = null, r = null;
|
|
416
|
-
try {
|
|
417
|
-
o(await e(t, a));
|
|
418
|
-
} catch (e) {
|
|
419
|
-
s(e);
|
|
420
|
-
}
|
|
421
|
-
}, n);
|
|
422
|
-
}));
|
|
423
|
-
}, g = (e, t) => {
|
|
424
|
-
let { onNextTick: n, onError: r, externalSignal: i, delay: a = 500, errorInitialDelay: o = 2e3, errorMaxDelay: s = 8e3 } = t, c = o, l = 0;
|
|
425
|
-
return (t, u) => {
|
|
426
|
-
let d = ++l;
|
|
427
|
-
return new Promise((f, p) => {
|
|
428
|
-
let m = async () => {
|
|
429
|
-
if (u.aborted || i?.aborted) {
|
|
430
|
-
p(new DOMException("Aborted by long polling lifecycle", "AbortError"));
|
|
431
|
-
return;
|
|
432
|
-
}
|
|
433
|
-
try {
|
|
434
|
-
let r = await e(t, u);
|
|
435
|
-
if (c = o, u.aborted || i?.aborted) {
|
|
436
|
-
p(new DOMException("Aborted by long polling lifecycle", "AbortError"));
|
|
437
|
-
return;
|
|
438
|
-
}
|
|
439
|
-
f(r), setTimeout(() => {
|
|
440
|
-
d === l && !u.aborted && !i?.aborted && n();
|
|
441
|
-
}, a);
|
|
442
|
-
} catch (e) {
|
|
443
|
-
if (e instanceof DOMException && e.name === "AbortError") {
|
|
444
|
-
p(e);
|
|
445
|
-
return;
|
|
446
|
-
}
|
|
447
|
-
p(e);
|
|
448
|
-
let t = c;
|
|
449
|
-
r(t, () => {
|
|
450
|
-
d === l && (c = Math.min(c * 2, s));
|
|
451
|
-
}), setTimeout(() => {
|
|
452
|
-
d === l && !u.aborted && !i?.aborted && n();
|
|
453
|
-
}, t);
|
|
454
|
-
}
|
|
455
|
-
}, h = () => {
|
|
456
|
-
p(new DOMException("Aborted by lifecycle event", "AbortError"));
|
|
457
|
-
};
|
|
458
|
-
if (u.addEventListener("abort", h), i && i.addEventListener("abort", h), u.aborted || i?.aborted) return h();
|
|
459
|
-
m();
|
|
460
|
-
});
|
|
461
|
-
};
|
|
462
|
-
}, _ = (e, t = {}) => {
|
|
463
|
-
let n = t.limit ?? 300, r = 0, i = null, a = null, o = null, s = null, c = null;
|
|
464
|
-
return (t, l) => {
|
|
465
|
-
let u = Date.now(), d = n - (u - r), f = () => {
|
|
466
|
-
i &&= (clearTimeout(i), null), s &&= (s(new DOMException("Aborted by resource signal during throttle", "AbortError")), o = null, null);
|
|
467
|
-
};
|
|
468
|
-
return d <= 0 ? (i &&= (clearTimeout(i), null), s &&= (s(new DOMException("Aborted due to newer direct throttle execution", "AbortError")), o = null, null), r = u, e(t, l)) : (s && s(new DOMException("Aborted due to newer throttled value", "AbortError")), new Promise((n, u) => {
|
|
469
|
-
if (a = t, o = n, s = u, c = l, l.aborted) return f();
|
|
470
|
-
l.addEventListener("abort", f), i ||= setTimeout(async () => {
|
|
471
|
-
i = null;
|
|
472
|
-
let t = a, n = o, l = s, u = c;
|
|
473
|
-
a = null, o = null, s = null, c = null, u.removeEventListener("abort", f);
|
|
474
|
-
try {
|
|
475
|
-
r = Date.now(), n(await e(t, u));
|
|
476
|
-
} catch (e) {
|
|
477
|
-
l(e);
|
|
478
|
-
}
|
|
479
|
-
}, d);
|
|
480
|
-
}));
|
|
481
|
-
};
|
|
482
|
-
}, v = (e, t = {}) => {
|
|
483
|
-
let n = t.limit ?? 300, r = t.ttl ?? 300 * 1e3, i = 0, a = null, o = null, s = null, c = null, l = null, u = /* @__PURE__ */ new Map(), d = (e) => typeof e == "object" && e ? JSON.stringify(e) : String(e);
|
|
484
|
-
return (t, f) => {
|
|
485
|
-
let p = Date.now(), m = n - (p - i);
|
|
486
|
-
d(t);
|
|
487
|
-
let h = () => {
|
|
488
|
-
a &&= (clearTimeout(a), null), c &&= (c(new DOMException("Aborted by resource signal during throttle", "AbortError")), s = null, null);
|
|
489
|
-
}, g = async (t, n) => {
|
|
490
|
-
let i = Date.now(), a = d(t), o = u.get(a);
|
|
491
|
-
if (o && i - o.timestamp < r) return o.data;
|
|
492
|
-
let s = await e(t, n);
|
|
493
|
-
return u.set(a, {
|
|
494
|
-
data: s,
|
|
495
|
-
timestamp: Date.now()
|
|
496
|
-
}), s;
|
|
497
|
-
};
|
|
498
|
-
return m <= 0 ? (a &&= (clearTimeout(a), null), c &&= (c(new DOMException("Aborted due to newer direct execution", "AbortError")), s = null, null), i = p, g(t, f)) : (c && c(new DOMException("Aborted due to newer throttled value", "AbortError")), new Promise((e, n) => {
|
|
499
|
-
if (o = t, s = e, c = n, l = f, f.aborted) return h();
|
|
500
|
-
f.addEventListener("abort", h), a ||= setTimeout(async () => {
|
|
501
|
-
a = null;
|
|
502
|
-
let e = o, t = s, n = c, r = l;
|
|
503
|
-
o = null, s = null, c = null, l = null, r.removeEventListener("abort", h);
|
|
504
|
-
try {
|
|
505
|
-
i = Date.now(), t(await g(e, r));
|
|
506
|
-
} catch (e) {
|
|
507
|
-
n(e);
|
|
508
|
-
}
|
|
509
|
-
}, m);
|
|
510
|
-
}));
|
|
511
|
-
};
|
|
512
|
-
}, y = (e, t) => {
|
|
513
|
-
let r = i(t);
|
|
514
|
-
n(() => {
|
|
515
|
-
r.current = t;
|
|
516
|
-
}, [t]), n(() => e.subscribe((e) => {
|
|
517
|
-
r.current(e);
|
|
518
|
-
}), [e]);
|
|
519
|
-
}, b = (e) => {
|
|
520
|
-
let i = r(() => typeof e == "function" ? e() : e, [e]), a = t((e) => i.subscribe(e), [i]), s = t(() => i.value, [i]);
|
|
521
|
-
return n(() => () => {
|
|
522
|
-
i && typeof i.destroy == "function" && i.destroy();
|
|
523
|
-
}, [i]), o(a, s);
|
|
524
|
-
}, x = (e) => {
|
|
525
|
-
let t = r(() => typeof e == "function" ? e() : e, [e]), [o, s] = a(t.value), c = i(s);
|
|
526
|
-
return n(() => {
|
|
527
|
-
c.current = s;
|
|
528
|
-
}, [s]), n(() => {
|
|
529
|
-
c.current(t.value);
|
|
530
|
-
let e = t.subscribe((e) => {
|
|
531
|
-
c.current(e);
|
|
532
|
-
});
|
|
533
|
-
return () => {
|
|
534
|
-
e(), t && typeof t.destroy == "function" && t.destroy();
|
|
535
|
-
};
|
|
536
|
-
}, [t]), o;
|
|
537
|
-
};
|
|
538
|
-
//#endregion
|
|
539
|
-
export { s as AbstractService, c as BaseREService, l as BaseREServiceEnhanced, d as ReactiveEngine, p as createObserver, f as createObserverComponent, y as useReactiveSubscription, b as useReactiveValue, x as useReactiveValue0, m as withCache, h as withDebounce, g as withLongPolling, _ as withThrottle, v as withThrottleAndCache };
|
|
540
|
-
|
|
541
|
-
//# sourceMappingURL=index.mjs.map
|
|
1
|
+
import { ReactiveEngine as e } from "./core.mjs";
|
|
2
|
+
import { AbstractService as t, BaseREService as n } from "./AbstractService.mjs";
|
|
3
|
+
import { BaseREServiceEnhanced as r } from "./BaseREServiceEnhanced.mjs";
|
|
4
|
+
export { t as AbstractService, n as BaseREService, r as BaseREServiceEnhanced, e as ReactiveEngine };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
const e=require("../core.cjs");let t=require("react");var n=class extends e.ReactiveEngine{reactAdapters={useState:t.useState,useEffect:t.useEffect};setReactAdapters(e,t){this.reactAdapters={useState:e,useEffect:t}}use(e){if(!this.reactAdapters)throw Error(`[React Error]: Адаптеры React не установлены. Вызовите engine.setReactAdapters(useState, useEffect).`);if(!e||typeof e.subscribe!=`function`){let t=`
|
|
2
|
+
[Reactive Error]: engine.use() получил некорректный объект!
|
|
3
|
+
Скорее всего, вы пытаетесь подписаться на свойство сервиса, которое не было инициализировано.
|
|
4
|
+
Проверьте, что в классе написано: public mySignal = this.engine.signal(...)
|
|
5
|
+
`;throw console.error(t,{item:e}),Error(t)}let[t,n]=this.reactAdapters.useState(e.value);return this.reactAdapters.useEffect(()=>e.subscribe(n),[e]),t}};exports.ReactiveEngine=n;
|
|
6
|
+
//# sourceMappingURL=ReactiveEngine4React.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReactiveEngine4React.cjs","names":[],"sources":["../../src/react/ReactiveEngine4React.ts"],"sourcesContent":["import { useState as useStateFromReact, useEffect as useEffectFromReact } from 'react'\nimport { CleanupFn, ReactiveEngine as __ReactiveEngine } from '../core'\n\nexport class ReactiveEngine extends __ReactiveEngine {\n // Описываем строгие типы для адаптеров React, чтобы не ломать встроенные типы React.\n private reactAdapters: {\n useState: typeof useStateFromReact;\n useEffect: typeof useEffectFromReact;\n } = {\n useState: useStateFromReact,\n useEffect: useEffectFromReact,\n };\n\n /**\n * Установка адаптеров React.\n * @function setReactAdapters\n * @param {Function} useState - Функция useState из React.\n * @param {Function} useEffect - Функция useEffect из React.\n * @returns {void}\n * @source\n */\n public setReactAdapters(\n useState: typeof useStateFromReact,\n useEffect: typeof useEffectFromReact\n ): void {\n this.reactAdapters = { useState, useEffect };\n }\n\n /**\n * Использование реактивного значения в React компоненте.\n * @template T\n * @function use\n * @param {{ value: T; subscribe: (cb: (v: T) => void) => CleanupFn }} item - Реактивный объект.\n * @returns {T} - Значение реактивного объекта.\n * @source\n */\n public use<T>(item: { value: T; subscribe: (cb: (v: T) => void) => CleanupFn }): T {\n if (!this.reactAdapters) {\n throw new Error(\"[React Error]: Адаптеры React не установлены. Вызовите engine.setReactAdapters(useState, useEffect).\");\n }\n\n // NOTE: (защита) проверяем, что нам передали объект сигнала\n if (!item || typeof item.subscribe !== 'function') {\n const errorMsg = `\n [Reactive Error]: engine.use() получил некорректный объект!\n Скорее всего, вы пытаетесь подписаться на свойство сервиса, которое не было инициализировано.\n Проверьте, что в классе написано: public mySignal = this.engine.signal(...)\n `;\n console.error(errorMsg, { item });\n throw new Error(errorMsg);\n }\n const [val, setVal] = this.reactAdapters.useState(item.value);\n\n this.reactAdapters.useEffect(\n () => {\n return item.subscribe(setVal);\n },\n [item]\n );\n\n return val;\n }\n}\n"],"mappings":"sDAGA,IAAa,EAAb,cAAoC,EAAA,cAAiB,CAEnD,cAGI,CACA,SAAU,EAAA,SACV,UAAW,EAAA,SACb,EAUF,iBACE,EACA,EACM,CACN,KAAK,cAAgB,CAAE,WAAU,WAAU,CAC7C,CAUA,IAAc,EAAqE,CACjF,GAAI,CAAC,KAAK,cACR,MAAU,MAAM,sGAAsG,EAIxH,GAAI,CAAC,GAAQ,OAAO,EAAK,WAAc,WAAY,CACjD,IAAM,EAAW;;;;QAMjB,MADA,QAAQ,MAAM,EAAU,CAAE,MAAK,CAAC,EACtB,MAAM,CAAQ,CAC1B,CACA,GAAM,CAAC,EAAK,GAAU,KAAK,cAAc,SAAS,EAAK,KAAK,EAS5D,OAPA,KAAK,cAAc,cAER,EAAK,UAAU,CAAM,EAE9B,CAAC,CAAI,CACP,EAEO,CACT,CACF"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { useState as useStateFromReact, useEffect as useEffectFromReact } from 'react';
|
|
2
|
+
import { CleanupFn, ReactiveEngine as ___ReactiveEngine } from '../core';
|
|
3
|
+
export declare class ReactiveEngine extends __ReactiveEngine {
|
|
4
|
+
private reactAdapters;
|
|
5
|
+
/**
|
|
6
|
+
* Установка адаптеров React.
|
|
7
|
+
* @function setReactAdapters
|
|
8
|
+
* @param {Function} useState - Функция useState из React.
|
|
9
|
+
* @param {Function} useEffect - Функция useEffect из React.
|
|
10
|
+
* @returns {void}
|
|
11
|
+
* @source
|
|
12
|
+
*/
|
|
13
|
+
setReactAdapters(useState: typeof useStateFromReact, useEffect: typeof useEffectFromReact): void;
|
|
14
|
+
/**
|
|
15
|
+
* Использование реактивного значения в React компоненте.
|
|
16
|
+
* @template T
|
|
17
|
+
* @function use
|
|
18
|
+
* @param {{ value: T; subscribe: (cb: (v: T) => void) => CleanupFn }} item - Реактивный объект.
|
|
19
|
+
* @returns {T} - Значение реактивного объекта.
|
|
20
|
+
* @source
|
|
21
|
+
*/
|
|
22
|
+
use<T>(item: {
|
|
23
|
+
value: T;
|
|
24
|
+
subscribe: (cb: (v: T) => void) => CleanupFn;
|
|
25
|
+
}): T;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=ReactiveEngine4React.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReactiveEngine4React.d.ts","sourceRoot":"","sources":["../../src/react/ReactiveEngine4React.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,iBAAiB,EAAE,SAAS,IAAI,kBAAkB,EAAE,MAAM,OAAO,CAAA;AACtF,OAAO,EAAE,SAAS,EAAE,cAAc,IAAI,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAEvE,qBAAa,cAAe,SAAQ,gBAAgB;IAElD,OAAO,CAAC,aAAa,CAMjB;IAEJ;;;;;;;OAOG;IACI,gBAAgB,CACrB,QAAQ,EAAE,OAAO,iBAAiB,EAClC,SAAS,EAAE,OAAO,kBAAkB,GACnC,IAAI;IAIP;;;;;;;OAOG;IACI,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE;QAAE,KAAK,EAAE,CAAC,CAAC;QAAC,SAAS,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,IAAI,KAAK,SAAS,CAAA;KAAE,GAAG,CAAC;CA0BnF"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ReactiveEngine as e } from "../core.mjs";
|
|
2
|
+
import { useEffect as t, useState as n } from "react";
|
|
3
|
+
//#region src/react/ReactiveEngine4React.ts
|
|
4
|
+
var r = class extends e {
|
|
5
|
+
reactAdapters = {
|
|
6
|
+
useState: n,
|
|
7
|
+
useEffect: t
|
|
8
|
+
};
|
|
9
|
+
setReactAdapters(e, t) {
|
|
10
|
+
this.reactAdapters = {
|
|
11
|
+
useState: e,
|
|
12
|
+
useEffect: t
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
use(e) {
|
|
16
|
+
if (!this.reactAdapters) throw Error("[React Error]: Адаптеры React не установлены. Вызовите engine.setReactAdapters(useState, useEffect).");
|
|
17
|
+
if (!e || typeof e.subscribe != "function") {
|
|
18
|
+
let t = "\n [Reactive Error]: engine.use() получил некорректный объект!\n Скорее всего, вы пытаетесь подписаться на свойство сервиса, которое не было инициализировано.\n Проверьте, что в классе написано: public mySignal = this.engine.signal(...)\n ";
|
|
19
|
+
throw console.error(t, { item: e }), Error(t);
|
|
20
|
+
}
|
|
21
|
+
let [t, n] = this.reactAdapters.useState(e.value);
|
|
22
|
+
return this.reactAdapters.useEffect(() => e.subscribe(n), [e]), t;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
//#endregion
|
|
26
|
+
export { r as ReactiveEngine };
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=ReactiveEngine4React.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReactiveEngine4React.mjs","names":[],"sources":["../../src/react/ReactiveEngine4React.ts"],"sourcesContent":["import { useState as useStateFromReact, useEffect as useEffectFromReact } from 'react'\nimport { CleanupFn, ReactiveEngine as __ReactiveEngine } from '../core'\n\nexport class ReactiveEngine extends __ReactiveEngine {\n // Описываем строгие типы для адаптеров React, чтобы не ломать встроенные типы React.\n private reactAdapters: {\n useState: typeof useStateFromReact;\n useEffect: typeof useEffectFromReact;\n } = {\n useState: useStateFromReact,\n useEffect: useEffectFromReact,\n };\n\n /**\n * Установка адаптеров React.\n * @function setReactAdapters\n * @param {Function} useState - Функция useState из React.\n * @param {Function} useEffect - Функция useEffect из React.\n * @returns {void}\n * @source\n */\n public setReactAdapters(\n useState: typeof useStateFromReact,\n useEffect: typeof useEffectFromReact\n ): void {\n this.reactAdapters = { useState, useEffect };\n }\n\n /**\n * Использование реактивного значения в React компоненте.\n * @template T\n * @function use\n * @param {{ value: T; subscribe: (cb: (v: T) => void) => CleanupFn }} item - Реактивный объект.\n * @returns {T} - Значение реактивного объекта.\n * @source\n */\n public use<T>(item: { value: T; subscribe: (cb: (v: T) => void) => CleanupFn }): T {\n if (!this.reactAdapters) {\n throw new Error(\"[React Error]: Адаптеры React не установлены. Вызовите engine.setReactAdapters(useState, useEffect).\");\n }\n\n // NOTE: (защита) проверяем, что нам передали объект сигнала\n if (!item || typeof item.subscribe !== 'function') {\n const errorMsg = `\n [Reactive Error]: engine.use() получил некорректный объект!\n Скорее всего, вы пытаетесь подписаться на свойство сервиса, которое не было инициализировано.\n Проверьте, что в классе написано: public mySignal = this.engine.signal(...)\n `;\n console.error(errorMsg, { item });\n throw new Error(errorMsg);\n }\n const [val, setVal] = this.reactAdapters.useState(item.value);\n\n this.reactAdapters.useEffect(\n () => {\n return item.subscribe(setVal);\n },\n [item]\n );\n\n return val;\n }\n}\n"],"mappings":";;;AAGA,IAAa,IAAb,cAAoC,EAAiB;CAEnD,gBAGI;EACU;EACC;CACb;CAUF,iBACE,GACA,GACM;EACN,KAAK,gBAAgB;GAAE;GAAU;EAAU;CAC7C;CAUA,IAAc,GAAqE;EACjF,IAAI,CAAC,KAAK,eACR,MAAU,MAAM,sGAAsG;EAIxH,IAAI,CAAC,KAAQ,OAAO,EAAK,aAAc,YAAY;GACjD,IAAM,IAAW;GAMjB,MADA,QAAQ,MAAM,GAAU,EAAE,QAAK,CAAC,GACtB,MAAM,CAAQ;EAC1B;EACA,IAAM,CAAC,GAAK,KAAU,KAAK,cAAc,SAAS,EAAK,KAAK;EAS5D,OAPA,KAAK,cAAc,gBAER,EAAK,UAAU,CAAM,GAE9B,CAAC,CAAI,CACP,GAEO;CACT;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.react.test.d.ts","sourceRoot":"","sources":["../../src/react/core.react.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require("../_virtual/_rolldown/runtime.cjs");let t=require("react");t=e.__toESM(t,1);var n=e=>({children:n})=>{let r=(0,t.useRef)(0),i=(0,t.useRef)(null),a=(0,t.useRef)(null),o=(0,t.useRef)(null),s=(0,t.useMemo)(()=>({subscribe(e){return i.current=e,()=>{i.current=null,a.current&&(a.current(),a.current=null,o.current=null)}},getSnapshot(){return r.current}}),[]);(0,t.useEffect)(()=>()=>{a.current&&a.current()},[]),a.current||(a.current=e.effect(()=>{i.current&&(r.current++,queueMicrotask(()=>{i.current&&i.current()}))}),o.current=Array.from(e.allEffects).pop());let c=e.activeEffect;e.activeEffect=o.current;let l=null;try{l=n()}finally{e.activeEffect=c}return(0,t.useSyncExternalStore)(s.subscribe,s.getSnapshot),l},r=e=>n=>{let r=r=>{let i=(0,t.useRef)(0),a=e,o=`activeEffect`in a?`activeEffect`:`_activeEffect`,s=(0,t.useRef)(null),{subscribe:c,getSnapshot:l}=(0,t.useMemo)(()=>({subscribe:t=>{let n=e.effect(()=>{i.current++,t()}),r=Array.from(a.allEffects||[]);return s.current=r[r.length-1],()=>{n(),s.current=null}},getSnapshot:()=>i.current}),[]);(0,t.useSyncExternalStore)(c,l,l);let u={cleanups:new Set,run:()=>{}},d=s.current||u,f=a[o];a[o]=d;let p=null;try{p=typeof n==`function`&&!n.prototype?.isReactComponent?n(r):t.default.createElement(n,r)}finally{a[o]=f}return p};return r.displayName=`Observer(${n.displayName||n.name||`Component`})`,r};exports.createObserver=r,exports.createObserverComponent=n;
|
|
2
|
+
//# sourceMappingURL=createObserver.cjs.map
|