@dougongjs/reactive 0.0.1
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/LICENSE +22 -0
- package/README.md +12 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +340 -0
- package/dist/observe.d.ts +21 -0
- package/dist/observe.d.ts.map +1 -0
- package/dist/protocol.d.ts +11 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/sync-result.d.ts +3 -0
- package/dist/sync-result.d.ts.map +1 -0
- package/package.json +46 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Dougong contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# @dougongjs/reactive
|
|
2
|
+
|
|
3
|
+
零依赖的响应式原语:`signal` / `computed` / `batch` / `observe`。
|
|
4
|
+
|
|
5
|
+
与 `@dougongjs/core` 互不依赖——`observe()` 是一个作用在结构化 `ObservationOwner` 上的自由函数,因此可以驱动 Core 的 Lifetime,而 Core 不需要知道它存在。
|
|
6
|
+
|
|
7
|
+
- 文档站:https://tangerg.github.io/dougong/
|
|
8
|
+
- 仓库:https://github.com/Tangerg/dougong
|
|
9
|
+
|
|
10
|
+
> 早期开发阶段(0.0.x),当前不承诺向后兼容。需要 Node.js >= 22 或等价的 ES2024 宿主。
|
|
11
|
+
|
|
12
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Readable } from './protocol';
|
|
2
|
+
export type { Disposable, Readable } from './protocol';
|
|
3
|
+
declare const dougongSignal: unique symbol;
|
|
4
|
+
/** A reactive node created by Dougong and safe to compose with computed(). */
|
|
5
|
+
export interface ReadonlySignal<T> extends Readable<T> {
|
|
6
|
+
readonly [dougongSignal]: true;
|
|
7
|
+
}
|
|
8
|
+
export interface Signal<T> extends ReadonlySignal<T> {
|
|
9
|
+
set(value: T): void;
|
|
10
|
+
}
|
|
11
|
+
export { observe, type ObservationLifetime, type ObservationOwner, type ObservationTask, type Observer, } from './observe';
|
|
12
|
+
export declare function batch<T>(callback: () => T): T;
|
|
13
|
+
export declare function signal<T>(initialValue: T): Signal<T>;
|
|
14
|
+
export declare function computed<T>(calculate: () => T): ReadonlySignal<T>;
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAc,QAAQ,EAAE,MAAM,YAAY,CAAC;AAGvD,YAAY,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEvD,OAAO,CAAC,MAAM,aAAa,EAAE,OAAO,MAAM,CAAC;AAE3C,8EAA8E;AAC9E,MAAM,WAAW,cAAc,CAAC,CAAC,CAAE,SAAQ,QAAQ,CAAC,CAAC,CAAC;IACpD,QAAQ,CAAC,CAAC,aAAa,CAAC,EAAE,IAAI,CAAC;CAChC;AAED,MAAM,WAAW,MAAM,CAAC,CAAC,CAAE,SAAQ,cAAc,CAAC,CAAC,CAAC;IAClD,GAAG,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;CACrB;AAED,OAAO,EACL,OAAO,EACP,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,QAAQ,GACd,MAAM,WAAW,CAAC;AAyFnB,wBAAgB,KAAK,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,GAAG,CAAC,CA4B7C;AAED,wBAAgB,MAAM,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAkCpD;AAED,wBAAgB,QAAQ,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,CAGjE"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
function d(e, t) {
|
|
2
|
+
if (b(e))
|
|
3
|
+
throw Promise.resolve(e).catch(() => {
|
|
4
|
+
}), new TypeError(t);
|
|
5
|
+
}
|
|
6
|
+
function b(e) {
|
|
7
|
+
return e === null || typeof e != "object" && typeof e != "function" ? !1 : typeof e.then == "function";
|
|
8
|
+
}
|
|
9
|
+
class E {
|
|
10
|
+
#i;
|
|
11
|
+
#t;
|
|
12
|
+
#r;
|
|
13
|
+
#h;
|
|
14
|
+
#n;
|
|
15
|
+
#e = { present: !1 };
|
|
16
|
+
#o = !1;
|
|
17
|
+
#s = "active";
|
|
18
|
+
#a;
|
|
19
|
+
#c;
|
|
20
|
+
#u;
|
|
21
|
+
constructor(t, s, i) {
|
|
22
|
+
this.#i = t, this.#t = s, this.#r = i;
|
|
23
|
+
}
|
|
24
|
+
start() {
|
|
25
|
+
const t = this.#t.get(), s = this.#i.lifetime("observation");
|
|
26
|
+
l(s), this.#n = s;
|
|
27
|
+
const i = this.#t.subscribe(() => this.#w());
|
|
28
|
+
v(i, "Readable.subscribe()"), this.#h = i, this.#l(t, s), this.#e = { present: !0, value: t };
|
|
29
|
+
const n = this.#i.spawn((r) => this.#y(r));
|
|
30
|
+
T(n), this.#a = n, n.result.then(
|
|
31
|
+
() => this.#v(n),
|
|
32
|
+
() => this.#v(n)
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
dispose() {
|
|
36
|
+
if (this.#u) return this.#u;
|
|
37
|
+
const t = Promise.withResolvers();
|
|
38
|
+
return this.#u = t.promise, this.#s = "disposed", this.#c?.(), this.#f().then(t.resolve, t.reject), t.promise;
|
|
39
|
+
}
|
|
40
|
+
async #f() {
|
|
41
|
+
const t = [];
|
|
42
|
+
if (await c(this.#b(), t), await c(this.#O(), t), await c(this.#p(), t), t.length === 1) throw t[0];
|
|
43
|
+
if (t.length > 1) throw new AggregateError(t, "Observation cleanup failed");
|
|
44
|
+
}
|
|
45
|
+
#w() {
|
|
46
|
+
this.#s === "active" && (this.#o = !0, this.#c?.());
|
|
47
|
+
}
|
|
48
|
+
async #y(t) {
|
|
49
|
+
try {
|
|
50
|
+
for (; this.#s === "active" && !t.aborted; )
|
|
51
|
+
for (await this.#m(t); this.#s === "active" && !t.aborted && this.#o; )
|
|
52
|
+
this.#o = !1, await this.#g();
|
|
53
|
+
} catch (s) {
|
|
54
|
+
if (this.#s === "stopped") throw s;
|
|
55
|
+
await this.#d([s], "Observation stopped after a replacement failed");
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
#m(t) {
|
|
59
|
+
return this.#o || this.#s !== "active" || t.aborted ? Promise.resolve() : new Promise((s) => {
|
|
60
|
+
const i = () => {
|
|
61
|
+
t.removeEventListener("abort", i), this.#c === i && (this.#c = void 0), s();
|
|
62
|
+
};
|
|
63
|
+
this.#c = i, t.addEventListener("abort", i, { once: !0 }), (this.#o || this.#s !== "active" || t.aborted) && i();
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
async #g() {
|
|
67
|
+
if (this.#s !== "active") return;
|
|
68
|
+
const t = this.#t.get();
|
|
69
|
+
if (this.#e.present && Object.is(t, this.#e.value)) return;
|
|
70
|
+
const s = this.#p();
|
|
71
|
+
if (s)
|
|
72
|
+
try {
|
|
73
|
+
await s.dispose();
|
|
74
|
+
} catch (n) {
|
|
75
|
+
return this.#d(
|
|
76
|
+
[n],
|
|
77
|
+
"Observation stopped because the previous lifetime could not be disposed"
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
if (this.#e = { present: !1 }, this.#s !== "active") return;
|
|
81
|
+
const i = this.#i.lifetime("observation");
|
|
82
|
+
l(i);
|
|
83
|
+
try {
|
|
84
|
+
this.#l(t, i);
|
|
85
|
+
} catch (n) {
|
|
86
|
+
try {
|
|
87
|
+
await i.dispose();
|
|
88
|
+
} catch (r) {
|
|
89
|
+
return this.#d(
|
|
90
|
+
[n, r],
|
|
91
|
+
"Observation callback failed and its resources could not be cleaned up"
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
throw n;
|
|
95
|
+
}
|
|
96
|
+
this.#n = i, this.#e = { present: !0, value: t };
|
|
97
|
+
}
|
|
98
|
+
#l(t, s) {
|
|
99
|
+
const i = this.#r(t, s);
|
|
100
|
+
d(i, "Observers must be synchronous; use lifetime.spawn() for async work");
|
|
101
|
+
}
|
|
102
|
+
#b() {
|
|
103
|
+
const t = this.#h;
|
|
104
|
+
return this.#h = void 0, t;
|
|
105
|
+
}
|
|
106
|
+
#p() {
|
|
107
|
+
const t = this.#n;
|
|
108
|
+
return this.#n = void 0, t;
|
|
109
|
+
}
|
|
110
|
+
#O() {
|
|
111
|
+
const t = this.#a;
|
|
112
|
+
return this.#a = void 0, t;
|
|
113
|
+
}
|
|
114
|
+
#v(t) {
|
|
115
|
+
this.#a === t && (this.#a = void 0);
|
|
116
|
+
}
|
|
117
|
+
async #d(t, s) {
|
|
118
|
+
throw this.#s = "stopped", this.#c?.(), await c(this.#b(), t), await c(this.#p(), t), t.length === 1 ? t[0] : new AggregateError(t, s);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
function j(e, t, s) {
|
|
122
|
+
if (!t || typeof t.get != "function" || typeof t.subscribe != "function")
|
|
123
|
+
throw new TypeError("observe() expects a readable source");
|
|
124
|
+
if (typeof s != "function") throw new TypeError("Observer must be a function");
|
|
125
|
+
if (!e || typeof e.cleanup != "function" || typeof e.lifetime != "function" || typeof e.spawn != "function")
|
|
126
|
+
throw new TypeError("observe() expects an observation owner");
|
|
127
|
+
const i = new E(e, t, s), n = e.cleanup(() => i.dispose());
|
|
128
|
+
v(n, "ObservationOwner.cleanup()");
|
|
129
|
+
try {
|
|
130
|
+
return i.start(), n;
|
|
131
|
+
} catch (r) {
|
|
132
|
+
throw i.dispose().catch(() => {
|
|
133
|
+
}), r;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
function v(e, t) {
|
|
137
|
+
if (!e || typeof e.dispose != "function")
|
|
138
|
+
throw new TypeError(`${t} must return a Disposable`);
|
|
139
|
+
}
|
|
140
|
+
function l(e) {
|
|
141
|
+
if (!e || typeof e.dispose != "function" || typeof e.cleanup != "function" || typeof e.lifetime != "function" || typeof e.spawn != "function")
|
|
142
|
+
throw new TypeError("ObservationOwner.lifetime() must return an ObservationLifetime");
|
|
143
|
+
}
|
|
144
|
+
function T(e) {
|
|
145
|
+
if (!e || typeof e.dispose != "function" || !b(e.result))
|
|
146
|
+
throw new TypeError("ObservationOwner.spawn() must return an ObservationTask");
|
|
147
|
+
}
|
|
148
|
+
async function c(e, t) {
|
|
149
|
+
if (e)
|
|
150
|
+
try {
|
|
151
|
+
await e.dispose();
|
|
152
|
+
} catch (s) {
|
|
153
|
+
t.push(s);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
let u = 0, a, f;
|
|
157
|
+
const p = /* @__PURE__ */ new WeakMap();
|
|
158
|
+
function w(e) {
|
|
159
|
+
return new S(e);
|
|
160
|
+
}
|
|
161
|
+
class S {
|
|
162
|
+
#i;
|
|
163
|
+
constructor(t) {
|
|
164
|
+
this.#i = t, Object.freeze(this);
|
|
165
|
+
}
|
|
166
|
+
dispose() {
|
|
167
|
+
const t = this.#i;
|
|
168
|
+
this.#i = void 0, t?.();
|
|
169
|
+
}
|
|
170
|
+
[Symbol.dispose]() {
|
|
171
|
+
this.dispose();
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
function z() {
|
|
175
|
+
const e = [];
|
|
176
|
+
for (; a?.size; ) {
|
|
177
|
+
const t = a;
|
|
178
|
+
a = /* @__PURE__ */ new Set(), m(t, e);
|
|
179
|
+
}
|
|
180
|
+
a = void 0, g(e);
|
|
181
|
+
}
|
|
182
|
+
function y(e) {
|
|
183
|
+
if (u) {
|
|
184
|
+
const s = a ??= /* @__PURE__ */ new Set();
|
|
185
|
+
for (const i of e) s.add(i);
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
const t = [];
|
|
189
|
+
m([...e], t), g(t);
|
|
190
|
+
}
|
|
191
|
+
function m(e, t) {
|
|
192
|
+
for (const s of e)
|
|
193
|
+
try {
|
|
194
|
+
s();
|
|
195
|
+
} catch (i) {
|
|
196
|
+
t.push(i);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
function g(e) {
|
|
200
|
+
if (e.length === 1) throw e[0];
|
|
201
|
+
if (e.length > 1)
|
|
202
|
+
throw new AggregateError(e, "Reactive subscribers failed");
|
|
203
|
+
}
|
|
204
|
+
function O(e) {
|
|
205
|
+
f?.(e);
|
|
206
|
+
}
|
|
207
|
+
function C(e) {
|
|
208
|
+
if (typeof e != "function") throw new TypeError("batch() expects a function");
|
|
209
|
+
u++;
|
|
210
|
+
let t;
|
|
211
|
+
try {
|
|
212
|
+
const s = e();
|
|
213
|
+
d(s, "Reactive batches must be synchronous"), t = { ok: !0, value: s };
|
|
214
|
+
} catch (s) {
|
|
215
|
+
t = { ok: !1, error: s };
|
|
216
|
+
} finally {
|
|
217
|
+
u--;
|
|
218
|
+
}
|
|
219
|
+
if (!u)
|
|
220
|
+
try {
|
|
221
|
+
z();
|
|
222
|
+
} catch (s) {
|
|
223
|
+
t = t.ok ? { ok: !1, error: s } : { ok: !1, error: new AggregateError([t.error, s], "Reactive batch failed") };
|
|
224
|
+
}
|
|
225
|
+
if (!t.ok) throw t.error;
|
|
226
|
+
return t.value;
|
|
227
|
+
}
|
|
228
|
+
function D(e) {
|
|
229
|
+
let t = e, s = 0;
|
|
230
|
+
const i = /* @__PURE__ */ new Set(), n = {
|
|
231
|
+
get() {
|
|
232
|
+
return O(n), t;
|
|
233
|
+
},
|
|
234
|
+
set(r) {
|
|
235
|
+
Object.is(t, r) || (t = r, s++, y(i));
|
|
236
|
+
},
|
|
237
|
+
subscribe(r) {
|
|
238
|
+
return k(r), i.add(r), w(() => i.delete(r));
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
return p.set(n, {
|
|
242
|
+
get version() {
|
|
243
|
+
return s;
|
|
244
|
+
},
|
|
245
|
+
refresh() {
|
|
246
|
+
}
|
|
247
|
+
}), Object.freeze(n);
|
|
248
|
+
}
|
|
249
|
+
function R(e) {
|
|
250
|
+
if (typeof e != "function") throw new TypeError("computed() expects a function");
|
|
251
|
+
return new L(e).view;
|
|
252
|
+
}
|
|
253
|
+
class L {
|
|
254
|
+
#i;
|
|
255
|
+
#t = /* @__PURE__ */ new Set();
|
|
256
|
+
#r = /* @__PURE__ */ new Map();
|
|
257
|
+
#h = { phase: "uninitialized" };
|
|
258
|
+
#n = !1;
|
|
259
|
+
#e = !0;
|
|
260
|
+
#o = 0;
|
|
261
|
+
view;
|
|
262
|
+
constructor(t) {
|
|
263
|
+
this.#i = t, this.view = Object.freeze({
|
|
264
|
+
get: () => this.#s(),
|
|
265
|
+
subscribe: (s) => this.#a(s)
|
|
266
|
+
}), p.set(this.view, this);
|
|
267
|
+
}
|
|
268
|
+
get version() {
|
|
269
|
+
return this.#o;
|
|
270
|
+
}
|
|
271
|
+
refresh() {
|
|
272
|
+
this.#f();
|
|
273
|
+
}
|
|
274
|
+
#s() {
|
|
275
|
+
return O(this.view), this.#f();
|
|
276
|
+
}
|
|
277
|
+
#a(t) {
|
|
278
|
+
k(t);
|
|
279
|
+
const s = this.#t.size === 0;
|
|
280
|
+
if (this.#t.add(t), s)
|
|
281
|
+
try {
|
|
282
|
+
this.#e = !0, this.#f();
|
|
283
|
+
} catch (i) {
|
|
284
|
+
throw this.#t.delete(t), this.#t.size || this.#u(), i;
|
|
285
|
+
}
|
|
286
|
+
return w(() => {
|
|
287
|
+
this.#t.delete(t), this.#t.size || this.#u();
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
#c = () => {
|
|
291
|
+
this.#e || (this.#e = !0, y(this.#t));
|
|
292
|
+
};
|
|
293
|
+
#u() {
|
|
294
|
+
for (const t of this.#r.values())
|
|
295
|
+
t.subscription?.dispose(), t.subscription = void 0;
|
|
296
|
+
}
|
|
297
|
+
#f() {
|
|
298
|
+
const t = this.#h;
|
|
299
|
+
if (t.phase === "cached" && !this.#e) {
|
|
300
|
+
for (const r of this.#r.values())
|
|
301
|
+
if (r.node.refresh(), r.version !== r.node.version) {
|
|
302
|
+
this.#e = !0;
|
|
303
|
+
break;
|
|
304
|
+
}
|
|
305
|
+
if (!this.#e) return t.value;
|
|
306
|
+
}
|
|
307
|
+
if (this.#n) throw new TypeError("Circular computed signal");
|
|
308
|
+
const s = /* @__PURE__ */ new Set(), i = f;
|
|
309
|
+
this.#n = !0, f = (r) => s.add(r);
|
|
310
|
+
let n;
|
|
311
|
+
try {
|
|
312
|
+
n = this.#i(), d(n, "Computed signal calculations must be synchronous");
|
|
313
|
+
} finally {
|
|
314
|
+
f = i, this.#n = !1;
|
|
315
|
+
}
|
|
316
|
+
for (const [r, o] of this.#r)
|
|
317
|
+
s.has(r) || (o.subscription?.dispose(), this.#r.delete(r));
|
|
318
|
+
for (const r of s) {
|
|
319
|
+
const o = p.get(r);
|
|
320
|
+
if (!o) continue;
|
|
321
|
+
const h = this.#r.get(r) ?? {
|
|
322
|
+
node: o,
|
|
323
|
+
version: o.version,
|
|
324
|
+
subscription: void 0
|
|
325
|
+
};
|
|
326
|
+
h.version = o.version, this.#t.size && !h.subscription && (h.subscription = r.subscribe(this.#c)), this.#r.set(r, h);
|
|
327
|
+
}
|
|
328
|
+
return (t.phase === "uninitialized" || !Object.is(t.value, n)) && this.#o++, this.#h = { phase: "cached", value: n }, this.#e = !1, n;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
function k(e) {
|
|
332
|
+
if (typeof e != "function")
|
|
333
|
+
throw new TypeError("Signal subscriber must be a function");
|
|
334
|
+
}
|
|
335
|
+
export {
|
|
336
|
+
C as batch,
|
|
337
|
+
R as computed,
|
|
338
|
+
j as observe,
|
|
339
|
+
D as signal
|
|
340
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Disposable, Readable } from './protocol';
|
|
2
|
+
export interface ObservationTask<T = void> extends Disposable {
|
|
3
|
+
readonly result: Promise<T>;
|
|
4
|
+
}
|
|
5
|
+
export interface ObservationLifetime extends Disposable {
|
|
6
|
+
cleanup(dispose: () => unknown): Disposable;
|
|
7
|
+
lifetime(label: string): ObservationLifetime;
|
|
8
|
+
spawn<T>(task: (signal: AbortSignal) => T | PromiseLike<T>): ObservationTask<T>;
|
|
9
|
+
}
|
|
10
|
+
export interface ObservationOwner<Child extends ObservationLifetime = ObservationLifetime> {
|
|
11
|
+
cleanup(dispose: () => unknown): Disposable;
|
|
12
|
+
lifetime(label: string): Child;
|
|
13
|
+
spawn<T>(task: (signal: AbortSignal) => T | PromiseLike<T>): ObservationTask<T>;
|
|
14
|
+
}
|
|
15
|
+
export type Observer<T, Child extends ObservationLifetime> = (value: T, lifetime: Child) => void;
|
|
16
|
+
/**
|
|
17
|
+
* Lifetime-aware synchronization built only from the public source and
|
|
18
|
+
* Lifetime protocols. It is a reactive-layer combinator, not a Core hook.
|
|
19
|
+
*/
|
|
20
|
+
export declare function observe<T, Child extends ObservationLifetime>(owner: ObservationOwner<Child>, source: Readable<T>, observer: Observer<T, Child>): Disposable;
|
|
21
|
+
//# sourceMappingURL=observe.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"observe.d.ts","sourceRoot":"","sources":["../src/observe.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAGvD,MAAM,WAAW,eAAe,CAAC,CAAC,GAAG,IAAI,CAAE,SAAQ,UAAU;IAC3D,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;CAC7B;AAED,MAAM,WAAW,mBAAoB,SAAQ,UAAU;IACrD,OAAO,CAAC,OAAO,EAAE,MAAM,OAAO,GAAG,UAAU,CAAC;IAC5C,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,mBAAmB,CAAC;IAC7C,KAAK,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,GAAG,eAAe,CAAC,CAAC,CAAC,CAAC;CACjF;AAED,MAAM,WAAW,gBAAgB,CAAC,KAAK,SAAS,mBAAmB,GAAG,mBAAmB;IACvF,OAAO,CAAC,OAAO,EAAE,MAAM,OAAO,GAAG,UAAU,CAAC;IAC5C,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,CAAC;IAC/B,KAAK,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,GAAG,eAAe,CAAC,CAAC,CAAC,CAAC;CACjF;AAED,MAAM,MAAM,QAAQ,CAAC,CAAC,EAAE,KAAK,SAAS,mBAAmB,IAAI,CAAC,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,KAAK,KAAK,IAAI,CAAC;AA+KjG;;;GAGG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,KAAK,SAAS,mBAAmB,EAC1D,KAAK,EAAE,gBAAgB,CAAC,KAAK,CAAC,EAC9B,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,EACnB,QAAQ,EAAE,QAAQ,CAAC,CAAC,EAAE,KAAK,CAAC,GAC3B,UAAU,CA0BZ"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface Disposable {
|
|
2
|
+
dispose(): void | Promise<void>;
|
|
3
|
+
[Symbol.dispose]?(): void;
|
|
4
|
+
[Symbol.asyncDispose]?(): Promise<void>;
|
|
5
|
+
}
|
|
6
|
+
/** Structural observable protocol shared by signals, extensions and diagnostics. */
|
|
7
|
+
export interface Readable<T> {
|
|
8
|
+
get(): T;
|
|
9
|
+
subscribe(listener: () => void): Disposable;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=protocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAU;IACzB,OAAO,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,IAAI,CAAC;IAC1B,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACzC;AAED,oFAAoF;AACpF,MAAM,WAAW,QAAQ,CAAC,CAAC;IACzB,GAAG,IAAI,CAAC,CAAC;IACT,SAAS,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,UAAU,CAAC;CAC7C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sync-result.d.ts","sourceRoot":"","sources":["../src/sync-result.ts"],"names":[],"mappings":"AAAA,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAQvE;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,WAAW,CAAC,OAAO,CAAC,CAGxE"}
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dougongjs/reactive",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"engines": {
|
|
6
|
+
"node": ">=22"
|
|
7
|
+
},
|
|
8
|
+
"sideEffects": false,
|
|
9
|
+
"files": [
|
|
10
|
+
"dist",
|
|
11
|
+
"README.md",
|
|
12
|
+
"LICENSE"
|
|
13
|
+
],
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"import": "./dist/index.js"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"description": "Zero-dependency signal, computed, batch and observe primitives.",
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"author": "Dougong contributors",
|
|
23
|
+
"homepage": "https://tangerg.github.io/dougong/",
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "git+https://github.com/Tangerg/dougong.git",
|
|
27
|
+
"directory": "packages/reactive"
|
|
28
|
+
},
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/Tangerg/dougong/issues"
|
|
31
|
+
},
|
|
32
|
+
"keywords": [
|
|
33
|
+
"plugin",
|
|
34
|
+
"plugin-system",
|
|
35
|
+
"dependency-injection",
|
|
36
|
+
"lifetime",
|
|
37
|
+
"service-container",
|
|
38
|
+
"typescript"
|
|
39
|
+
],
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "public"
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"build": "vite build"
|
|
45
|
+
}
|
|
46
|
+
}
|