@reckona/mreact-reactive-core 0.0.173 → 0.0.175
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cell-subscription.d.ts","sourceRoot":"","sources":["../src/cell-subscription.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"cell-subscription.d.ts","sourceRoot":"","sources":["../src/cell-subscription.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAkB/C,wBAAgB,aAAa,CAAC,CAAC,EAC7B,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC,EACrB,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,GAC3B,CAAC,MAAM,IAAI,CAAC,GAAG,SAAS,CAsB1B"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getCellSource } from "./cell.js";
|
|
2
2
|
import { queueComputation } from "./scheduler.js";
|
|
3
3
|
import { runtimeState } from "./state.js";
|
|
4
|
-
import { addSourceSubscriber
|
|
4
|
+
import { addSourceSubscriber } from "./tracking.js";
|
|
5
5
|
const CELL_SUBSCRIPTION_COMPUTATION_METHODS = {
|
|
6
6
|
markDirty: cellSubscriptionMarkDirty,
|
|
7
7
|
run: cellSubscriptionRun,
|
|
@@ -13,7 +13,6 @@ export function subscribeCell(cell, listener) {
|
|
|
13
13
|
return undefined;
|
|
14
14
|
}
|
|
15
15
|
const computation = {
|
|
16
|
-
cell,
|
|
17
16
|
dispose: CELL_SUBSCRIPTION_COMPUTATION_METHODS.dispose,
|
|
18
17
|
disposed: false,
|
|
19
18
|
id: runtimeState.nextComputationId,
|
|
@@ -35,7 +34,7 @@ function cellSubscriptionRun() {
|
|
|
35
34
|
if (subscription.disposed) {
|
|
36
35
|
return;
|
|
37
36
|
}
|
|
38
|
-
subscription.listener(subscription.
|
|
37
|
+
subscription.listener(subscription.source.value);
|
|
39
38
|
}
|
|
40
39
|
function cellSubscriptionDispose() {
|
|
41
40
|
const subscription = this;
|
|
@@ -43,8 +42,43 @@ function cellSubscriptionDispose() {
|
|
|
43
42
|
return;
|
|
44
43
|
}
|
|
45
44
|
subscription.disposed = true;
|
|
46
|
-
subscription.queued
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
if (subscription.queued) {
|
|
46
|
+
subscription.queued = false;
|
|
47
|
+
runtimeState.pendingComputed.delete(subscription);
|
|
48
|
+
}
|
|
49
|
+
const source = subscription.source;
|
|
50
|
+
const subscribers = source.subscribers;
|
|
51
|
+
if (subscribers === subscription) {
|
|
52
|
+
source.subscribers = null;
|
|
53
|
+
const onNoSubscribers = source.onNoSubscribers;
|
|
54
|
+
if (onNoSubscribers !== undefined) {
|
|
55
|
+
onNoSubscribers();
|
|
56
|
+
}
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
removeCellSubscriptionSourceSubscriber(subscription.source, subscription);
|
|
60
|
+
}
|
|
61
|
+
function removeCellSubscriptionSourceSubscriber(source, subscription) {
|
|
62
|
+
const subscribers = source.subscribers;
|
|
63
|
+
const computation = subscription;
|
|
64
|
+
const current = subscribers;
|
|
65
|
+
if (current === subscription) {
|
|
66
|
+
source.subscribers = null;
|
|
67
|
+
const onNoSubscribers = source.onNoSubscribers;
|
|
68
|
+
if (onNoSubscribers !== undefined) {
|
|
69
|
+
onNoSubscribers();
|
|
70
|
+
}
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (!(subscribers instanceof Set) || !subscribers.delete(computation)) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (subscribers.size === 0) {
|
|
77
|
+
source.subscribers = null;
|
|
78
|
+
const onNoSubscribers = source.onNoSubscribers;
|
|
79
|
+
if (onNoSubscribers !== undefined) {
|
|
80
|
+
onNoSubscribers();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
49
83
|
}
|
|
50
84
|
//# sourceMappingURL=cell-subscription.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cell-subscription.js","sourceRoot":"","sources":["../src/cell-subscription.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAyC,MAAM,YAAY,CAAC;AAEjF,OAAO,EAAE,mBAAmB,EAAE,
|
|
1
|
+
{"version":3,"file":"cell-subscription.js","sourceRoot":"","sources":["../src/cell-subscription.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAyC,MAAM,YAAY,CAAC;AAEjF,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAWpD,MAAM,qCAAqC,GAAG;IAC5C,SAAS,EAAE,yBAAyB;IACpC,GAAG,EAAE,mBAAmB;IACxB,OAAO,EAAE,uBAAuB;CACoC,CAAC;AAEvE,MAAM,UAAU,aAAa,CAC3B,IAAqB,EACrB,QAA4B;IAE5B,MAAM,MAAM,GAAG,aAAa,CAAC,IAAI,CAAmC,CAAC;IAErE,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,WAAW,GAAwB;QACvC,OAAO,EAAE,qCAAqC,CAAC,OAAO;QACtD,QAAQ,EAAE,KAAK;QACf,EAAE,EAAE,YAAY,CAAC,iBAAiB;QAClC,QAAQ;QACR,SAAS,EAAE,qCAAqC,CAAC,SAAS;QAC1D,MAAM,EAAE,KAAK;QACb,GAAG,EAAE,qCAAqC,CAAC,GAAG;QAC9C,MAAM;KACP,CAAC;IAEF,YAAY,CAAC,iBAA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AAM,CAAC,WAAW,CAAC;IACvC,MAAM,WAAW,GAAG,YAA8C,CAAC;IACnE,MAAM,OAAO,GAAG,WAAsB,CAAC;IAEvC,IAAI,OAAO,KAAK,YAAY,EAAE,CAAC;QAC7B,MAAM,CAAC,WAAW,GAAG,IAAI,CAAC;QAC1B,MAAM,eAAe,GAAG,MAAM,CAAC,eAAe,CAAC;QAC/C,IAAI,eAAe,KAAK,SAAS,EAAE,CAAC;YAClC,eAAe,EAAE,CAAC;QACpB,CAAC;QACD,OAAO;IACT,CAAC;IAED,IAAI,CAAC,CAAC,WAAW,YAAY,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC;QACtE,OAAO;IACT,CAAC;IAED,IAAI,WAAW,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC;QAC3B,MAAM,CAAC,WAAW,GAAG,IAAI,CAAC;QAC1B,MAAM,eAAe,GAAG,MAAM,CAAC,eAAe,CAAC;QAC/C,IAAI,eAAe,KAAK,SAAS,EAAE,CAAC;YAClC,eAAe,EAAE,CAAC;QACpB,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import { getCellSource } from \"./cell.js\";\nimport { queueComputation } from \"./scheduler.js\";\nimport { runtimeState, type ReactiveComputation, type Source } from \"./state.js\";\nimport type { ReadonlyCell } from \"./types.js\";\nimport { addSourceSubscriber } from \"./tracking.js\";\n\ninterface CellValueSource<T> extends Source {\n value: T;\n}\n\ninterface CellSubscription<T> extends Omit<ReactiveComputation, \"deps\"> {\n listener: (value: T) => void;\n source: CellValueSource<T>;\n}\n\nconst CELL_SUBSCRIPTION_COMPUTATION_METHODS = {\n markDirty: cellSubscriptionMarkDirty,\n run: cellSubscriptionRun,\n dispose: cellSubscriptionDispose,\n} satisfies Pick<ReactiveComputation, \"markDirty\" | \"run\" | \"dispose\">;\n\nexport function subscribeCell<T>(\n cell: ReadonlyCell<T>,\n listener: (value: T) => void,\n): (() => void) | undefined {\n const source = getCellSource(cell) as CellValueSource<T> | undefined;\n\n if (source === undefined) {\n return undefined;\n }\n\n const computation: CellSubscription<T> = {\n dispose: CELL_SUBSCRIPTION_COMPUTATION_METHODS.dispose,\n disposed: false,\n id: runtimeState.nextComputationId,\n listener,\n markDirty: CELL_SUBSCRIPTION_COMPUTATION_METHODS.markDirty,\n queued: false,\n run: CELL_SUBSCRIPTION_COMPUTATION_METHODS.run,\n source,\n };\n\n runtimeState.nextComputationId += 1;\n addSourceSubscriber(source, computation as unknown as ReactiveComputation);\n\n return () => computation.dispose();\n}\n\nfunction cellSubscriptionMarkDirty(this: ReactiveComputation): void {\n queueComputation(this);\n}\n\nfunction cellSubscriptionRun(this: ReactiveComputation): void {\n const subscription = this as unknown as CellSubscription<unknown>;\n\n if (subscription.disposed) {\n return;\n }\n\n subscription.listener(subscription.source.value);\n}\n\nfunction cellSubscriptionDispose(this: ReactiveComputation): void {\n const subscription = this as unknown as CellSubscription<unknown>;\n\n if (subscription.disposed) {\n return;\n }\n\n subscription.disposed = true;\n if (subscription.queued) {\n subscription.queued = false;\n runtimeState.pendingComputed.delete(subscription as unknown as ReactiveComputation);\n }\n\n const source = subscription.source;\n const subscribers = source.subscribers;\n\n if ((subscribers as unknown) === subscription) {\n source.subscribers = null;\n const onNoSubscribers = source.onNoSubscribers;\n if (onNoSubscribers !== undefined) {\n onNoSubscribers();\n }\n return;\n }\n\n removeCellSubscriptionSourceSubscriber(subscription.source, subscription);\n}\n\nfunction removeCellSubscriptionSourceSubscriber(\n source: Source,\n subscription: CellSubscription<unknown>,\n): void {\n const subscribers = source.subscribers;\n const computation = subscription as unknown as ReactiveComputation;\n const current = subscribers as unknown;\n\n if (current === subscription) {\n source.subscribers = null;\n const onNoSubscribers = source.onNoSubscribers;\n if (onNoSubscribers !== undefined) {\n onNoSubscribers();\n }\n return;\n }\n\n if (!(subscribers instanceof Set) || !subscribers.delete(computation)) {\n return;\n }\n\n if (subscribers.size === 0) {\n source.subscribers = null;\n const onNoSubscribers = source.onNoSubscribers;\n if (onNoSubscribers !== undefined) {\n onNoSubscribers();\n }\n }\n}\n"]}
|
package/package.json
CHANGED
package/src/cell-subscription.ts
CHANGED
|
@@ -2,12 +2,15 @@ import { getCellSource } from "./cell.js";
|
|
|
2
2
|
import { queueComputation } from "./scheduler.js";
|
|
3
3
|
import { runtimeState, type ReactiveComputation, type Source } from "./state.js";
|
|
4
4
|
import type { ReadonlyCell } from "./types.js";
|
|
5
|
-
import { addSourceSubscriber
|
|
5
|
+
import { addSourceSubscriber } from "./tracking.js";
|
|
6
|
+
|
|
7
|
+
interface CellValueSource<T> extends Source {
|
|
8
|
+
value: T;
|
|
9
|
+
}
|
|
6
10
|
|
|
7
11
|
interface CellSubscription<T> extends Omit<ReactiveComputation, "deps"> {
|
|
8
|
-
cell: ReadonlyCell<T>;
|
|
9
12
|
listener: (value: T) => void;
|
|
10
|
-
source:
|
|
13
|
+
source: CellValueSource<T>;
|
|
11
14
|
}
|
|
12
15
|
|
|
13
16
|
const CELL_SUBSCRIPTION_COMPUTATION_METHODS = {
|
|
@@ -20,14 +23,13 @@ export function subscribeCell<T>(
|
|
|
20
23
|
cell: ReadonlyCell<T>,
|
|
21
24
|
listener: (value: T) => void,
|
|
22
25
|
): (() => void) | undefined {
|
|
23
|
-
const source = getCellSource(cell);
|
|
26
|
+
const source = getCellSource(cell) as CellValueSource<T> | undefined;
|
|
24
27
|
|
|
25
28
|
if (source === undefined) {
|
|
26
29
|
return undefined;
|
|
27
30
|
}
|
|
28
31
|
|
|
29
32
|
const computation: CellSubscription<T> = {
|
|
30
|
-
cell,
|
|
31
33
|
dispose: CELL_SUBSCRIPTION_COMPUTATION_METHODS.dispose,
|
|
32
34
|
disposed: false,
|
|
33
35
|
id: runtimeState.nextComputationId,
|
|
@@ -55,7 +57,7 @@ function cellSubscriptionRun(this: ReactiveComputation): void {
|
|
|
55
57
|
return;
|
|
56
58
|
}
|
|
57
59
|
|
|
58
|
-
subscription.listener(subscription.
|
|
60
|
+
subscription.listener(subscription.source.value);
|
|
59
61
|
}
|
|
60
62
|
|
|
61
63
|
function cellSubscriptionDispose(this: ReactiveComputation): void {
|
|
@@ -66,10 +68,52 @@ function cellSubscriptionDispose(this: ReactiveComputation): void {
|
|
|
66
68
|
}
|
|
67
69
|
|
|
68
70
|
subscription.disposed = true;
|
|
69
|
-
subscription.queued
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
71
|
+
if (subscription.queued) {
|
|
72
|
+
subscription.queued = false;
|
|
73
|
+
runtimeState.pendingComputed.delete(subscription as unknown as ReactiveComputation);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const source = subscription.source;
|
|
77
|
+
const subscribers = source.subscribers;
|
|
78
|
+
|
|
79
|
+
if ((subscribers as unknown) === subscription) {
|
|
80
|
+
source.subscribers = null;
|
|
81
|
+
const onNoSubscribers = source.onNoSubscribers;
|
|
82
|
+
if (onNoSubscribers !== undefined) {
|
|
83
|
+
onNoSubscribers();
|
|
84
|
+
}
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
removeCellSubscriptionSourceSubscriber(subscription.source, subscription);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function removeCellSubscriptionSourceSubscriber(
|
|
92
|
+
source: Source,
|
|
93
|
+
subscription: CellSubscription<unknown>,
|
|
94
|
+
): void {
|
|
95
|
+
const subscribers = source.subscribers;
|
|
96
|
+
const computation = subscription as unknown as ReactiveComputation;
|
|
97
|
+
const current = subscribers as unknown;
|
|
98
|
+
|
|
99
|
+
if (current === subscription) {
|
|
100
|
+
source.subscribers = null;
|
|
101
|
+
const onNoSubscribers = source.onNoSubscribers;
|
|
102
|
+
if (onNoSubscribers !== undefined) {
|
|
103
|
+
onNoSubscribers();
|
|
104
|
+
}
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (!(subscribers instanceof Set) || !subscribers.delete(computation)) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (subscribers.size === 0) {
|
|
113
|
+
source.subscribers = null;
|
|
114
|
+
const onNoSubscribers = source.onNoSubscribers;
|
|
115
|
+
if (onNoSubscribers !== undefined) {
|
|
116
|
+
onNoSubscribers();
|
|
117
|
+
}
|
|
118
|
+
}
|
|
75
119
|
}
|