@flexsurfer/reflex 0.1.23 → 0.1.24
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/index.cjs +33 -5
- package/dist/index.mjs +33 -5
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -127,12 +127,16 @@ function clearHandlers(kind, id) {
|
|
|
127
127
|
for (const k in kindToIdToHandler) {
|
|
128
128
|
kindToIdToHandler[k] = {};
|
|
129
129
|
}
|
|
130
|
+
clearRootSubSources();
|
|
130
131
|
} else if (id == null) {
|
|
131
132
|
if (!(kind in kindToIdToHandler)) {
|
|
132
133
|
consoleLog("error", `[reflex] Unknown kind: ${kind}`);
|
|
133
134
|
return;
|
|
134
135
|
}
|
|
135
136
|
kindToIdToHandler[kind] = {};
|
|
137
|
+
if (kind === "sub") {
|
|
138
|
+
clearRootSubSources();
|
|
139
|
+
}
|
|
136
140
|
} else {
|
|
137
141
|
if (kindToIdToHandler[kind][id]) {
|
|
138
142
|
delete kindToIdToHandler[kind][id];
|
|
@@ -161,6 +165,16 @@ function clearReactions(id) {
|
|
|
161
165
|
reactionsRegistry.delete(id);
|
|
162
166
|
}
|
|
163
167
|
}
|
|
168
|
+
var rootSubIdBySource = /* @__PURE__ */ new Map();
|
|
169
|
+
function setRootSubSource(subId, sourceKey) {
|
|
170
|
+
rootSubIdBySource.set(sourceKey, subId);
|
|
171
|
+
}
|
|
172
|
+
function getRootSubIdBySource(sourceKey) {
|
|
173
|
+
return rootSubIdBySource.get(sourceKey);
|
|
174
|
+
}
|
|
175
|
+
function clearRootSubSources() {
|
|
176
|
+
rootSubIdBySource.clear();
|
|
177
|
+
}
|
|
164
178
|
function clearSubs() {
|
|
165
179
|
clearReactions();
|
|
166
180
|
clearHandlers("sub");
|
|
@@ -230,7 +244,14 @@ function updateAppDbWithPatches(newDb, patches) {
|
|
|
230
244
|
const pathSegments = patch.path;
|
|
231
245
|
if (pathSegments.length > 0) {
|
|
232
246
|
const rootKey = pathSegments[0];
|
|
233
|
-
|
|
247
|
+
if (typeof rootKey !== "string") {
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
const subId = getRootSubIdBySource(rootKey);
|
|
251
|
+
if (!subId) {
|
|
252
|
+
continue;
|
|
253
|
+
}
|
|
254
|
+
const subVectorKey = JSON.stringify([subId]);
|
|
234
255
|
const reaction = getReaction(subVectorKey);
|
|
235
256
|
if (reaction) {
|
|
236
257
|
if (!reaction.isRoot) {
|
|
@@ -1089,16 +1110,23 @@ var Reaction = class _Reaction {
|
|
|
1089
1110
|
// src/subs.ts
|
|
1090
1111
|
var KIND4 = "sub";
|
|
1091
1112
|
var KIND_DEPS = "subDeps";
|
|
1113
|
+
function registerRootSub(id, sourceKey) {
|
|
1114
|
+
const conflictingSubId = getRootSubIdBySource(sourceKey);
|
|
1115
|
+
if (conflictingSubId && conflictingSubId !== id) {
|
|
1116
|
+
consoleLog("error", `[reflex] Subscription with id '${id}' will be overridden. Root key '${sourceKey}' is already used by subscription '${conflictingSubId}'.`);
|
|
1117
|
+
}
|
|
1118
|
+
setRootSubSource(id, sourceKey);
|
|
1119
|
+
registerHandler(KIND4, id, () => getAppDb()[sourceKey]);
|
|
1120
|
+
registerHandler(KIND_DEPS, id, () => []);
|
|
1121
|
+
}
|
|
1092
1122
|
function regSub(id, computeFn, depsFn, config) {
|
|
1093
1123
|
if (hasHandler(KIND4, id)) {
|
|
1094
1124
|
consoleLog("warn", `[reflex] Overriding. Subscription '${id}' already registered.`);
|
|
1095
1125
|
}
|
|
1096
1126
|
if (!computeFn) {
|
|
1097
|
-
|
|
1098
|
-
registerHandler(KIND_DEPS, id, () => []);
|
|
1127
|
+
registerRootSub(id, id);
|
|
1099
1128
|
} else if (typeof computeFn === "string") {
|
|
1100
|
-
|
|
1101
|
-
registerHandler(KIND_DEPS, id, () => []);
|
|
1129
|
+
registerRootSub(id, computeFn);
|
|
1102
1130
|
} else {
|
|
1103
1131
|
if (!depsFn) {
|
|
1104
1132
|
consoleLog("error", `[reflex] Subscription '${id}' has computeFn but missing depsFn. Computed subscriptions must specify their dependencies.`);
|
package/dist/index.mjs
CHANGED
|
@@ -49,12 +49,16 @@ function clearHandlers(kind, id) {
|
|
|
49
49
|
for (const k in kindToIdToHandler) {
|
|
50
50
|
kindToIdToHandler[k] = {};
|
|
51
51
|
}
|
|
52
|
+
clearRootSubSources();
|
|
52
53
|
} else if (id == null) {
|
|
53
54
|
if (!(kind in kindToIdToHandler)) {
|
|
54
55
|
consoleLog("error", `[reflex] Unknown kind: ${kind}`);
|
|
55
56
|
return;
|
|
56
57
|
}
|
|
57
58
|
kindToIdToHandler[kind] = {};
|
|
59
|
+
if (kind === "sub") {
|
|
60
|
+
clearRootSubSources();
|
|
61
|
+
}
|
|
58
62
|
} else {
|
|
59
63
|
if (kindToIdToHandler[kind][id]) {
|
|
60
64
|
delete kindToIdToHandler[kind][id];
|
|
@@ -83,6 +87,16 @@ function clearReactions(id) {
|
|
|
83
87
|
reactionsRegistry.delete(id);
|
|
84
88
|
}
|
|
85
89
|
}
|
|
90
|
+
var rootSubIdBySource = /* @__PURE__ */ new Map();
|
|
91
|
+
function setRootSubSource(subId, sourceKey) {
|
|
92
|
+
rootSubIdBySource.set(sourceKey, subId);
|
|
93
|
+
}
|
|
94
|
+
function getRootSubIdBySource(sourceKey) {
|
|
95
|
+
return rootSubIdBySource.get(sourceKey);
|
|
96
|
+
}
|
|
97
|
+
function clearRootSubSources() {
|
|
98
|
+
rootSubIdBySource.clear();
|
|
99
|
+
}
|
|
86
100
|
function clearSubs() {
|
|
87
101
|
clearReactions();
|
|
88
102
|
clearHandlers("sub");
|
|
@@ -152,7 +166,14 @@ function updateAppDbWithPatches(newDb, patches) {
|
|
|
152
166
|
const pathSegments = patch.path;
|
|
153
167
|
if (pathSegments.length > 0) {
|
|
154
168
|
const rootKey = pathSegments[0];
|
|
155
|
-
|
|
169
|
+
if (typeof rootKey !== "string") {
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
const subId = getRootSubIdBySource(rootKey);
|
|
173
|
+
if (!subId) {
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
const subVectorKey = JSON.stringify([subId]);
|
|
156
177
|
const reaction = getReaction(subVectorKey);
|
|
157
178
|
if (reaction) {
|
|
158
179
|
if (!reaction.isRoot) {
|
|
@@ -1011,16 +1032,23 @@ var Reaction = class _Reaction {
|
|
|
1011
1032
|
// src/subs.ts
|
|
1012
1033
|
var KIND4 = "sub";
|
|
1013
1034
|
var KIND_DEPS = "subDeps";
|
|
1035
|
+
function registerRootSub(id, sourceKey) {
|
|
1036
|
+
const conflictingSubId = getRootSubIdBySource(sourceKey);
|
|
1037
|
+
if (conflictingSubId && conflictingSubId !== id) {
|
|
1038
|
+
consoleLog("error", `[reflex] Subscription with id '${id}' will be overridden. Root key '${sourceKey}' is already used by subscription '${conflictingSubId}'.`);
|
|
1039
|
+
}
|
|
1040
|
+
setRootSubSource(id, sourceKey);
|
|
1041
|
+
registerHandler(KIND4, id, () => getAppDb()[sourceKey]);
|
|
1042
|
+
registerHandler(KIND_DEPS, id, () => []);
|
|
1043
|
+
}
|
|
1014
1044
|
function regSub(id, computeFn, depsFn, config) {
|
|
1015
1045
|
if (hasHandler(KIND4, id)) {
|
|
1016
1046
|
consoleLog("warn", `[reflex] Overriding. Subscription '${id}' already registered.`);
|
|
1017
1047
|
}
|
|
1018
1048
|
if (!computeFn) {
|
|
1019
|
-
|
|
1020
|
-
registerHandler(KIND_DEPS, id, () => []);
|
|
1049
|
+
registerRootSub(id, id);
|
|
1021
1050
|
} else if (typeof computeFn === "string") {
|
|
1022
|
-
|
|
1023
|
-
registerHandler(KIND_DEPS, id, () => []);
|
|
1051
|
+
registerRootSub(id, computeFn);
|
|
1024
1052
|
} else {
|
|
1025
1053
|
if (!depsFn) {
|
|
1026
1054
|
consoleLog("error", `[reflex] Subscription '${id}' has computeFn but missing depsFn. Computed subscriptions must specify their dependencies.`);
|