@expressive/mvc 0.9.6 → 0.10.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/lib/index.d.ts +81 -89
- package/lib/index.esm.js +166 -162
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +166 -163
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -8,7 +8,10 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
|
8
8
|
|
|
9
9
|
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
10
10
|
|
|
11
|
-
const { assign, create, defineProperties, defineProperty, entries, getPrototypeOf, getOwnPropertyNames, getOwnPropertyDescriptor, getOwnPropertySymbols, values } = Object;
|
|
11
|
+
const { assign, create, defineProperties, defineProperty, entries, getPrototypeOf, getOwnPropertyNames, getOwnPropertyDescriptor, getOwnPropertySymbols, values } = Object;
|
|
12
|
+
function unique(array) {
|
|
13
|
+
return Array.from(new Set(array));
|
|
14
|
+
}
|
|
12
15
|
|
|
13
16
|
class Issue extends Error {
|
|
14
17
|
constructor() {
|
|
@@ -659,6 +662,7 @@ function createValueEffect(callback) {
|
|
|
659
662
|
function ref(arg, mapper) {
|
|
660
663
|
return add(function ref(key) {
|
|
661
664
|
let value = {};
|
|
665
|
+
this.state.set(key, undefined);
|
|
662
666
|
if (typeof arg != "object")
|
|
663
667
|
value = createRef(this, key, arg);
|
|
664
668
|
else
|
|
@@ -955,31 +959,31 @@ const Oops$6 = issues({
|
|
|
955
959
|
StrictNoUpdate: () => `Update is not expected but one is in progress!`
|
|
956
960
|
});
|
|
957
961
|
function addEventListener(source, arg1, arg2, arg3) {
|
|
962
|
+
if (typeof arg1 == "string")
|
|
963
|
+
arg1 = [arg1];
|
|
964
|
+
return Control.for(source, control => {
|
|
965
|
+
for (const key of arg1)
|
|
966
|
+
try {
|
|
967
|
+
void source[key];
|
|
968
|
+
}
|
|
969
|
+
catch (e) { }
|
|
970
|
+
const removeListener = control.addListener(key => {
|
|
971
|
+
if (!key && !arg1.length)
|
|
972
|
+
arg2.call(source, []);
|
|
973
|
+
if (arg1.includes(key)) {
|
|
974
|
+
if (arg3)
|
|
975
|
+
removeListener();
|
|
976
|
+
return arg2.bind(source);
|
|
977
|
+
}
|
|
978
|
+
});
|
|
979
|
+
return removeListener;
|
|
980
|
+
});
|
|
981
|
+
}
|
|
982
|
+
function awaitUpdate(source, arg1, arg2) {
|
|
958
983
|
const single = typeof arg1 == "string";
|
|
959
984
|
const keys = typeof arg1 == "string" ? [arg1] :
|
|
960
985
|
typeof arg1 == "object" ? arg1 :
|
|
961
986
|
undefined;
|
|
962
|
-
if (typeof arg2 == "function" && keys)
|
|
963
|
-
return Control.for(source, control => {
|
|
964
|
-
for (const key of keys)
|
|
965
|
-
try {
|
|
966
|
-
void source[key];
|
|
967
|
-
}
|
|
968
|
-
catch (e) { }
|
|
969
|
-
const invoke = single
|
|
970
|
-
? () => arg2.call(source, control.state.get(arg1), arg1)
|
|
971
|
-
: (frame) => arg2.call(source, frame);
|
|
972
|
-
const removeListener = control.addListener(key => {
|
|
973
|
-
if (!key && !keys.length)
|
|
974
|
-
invoke([]);
|
|
975
|
-
if (keys.includes(key)) {
|
|
976
|
-
if (arg3)
|
|
977
|
-
removeListener();
|
|
978
|
-
return invoke;
|
|
979
|
-
}
|
|
980
|
-
});
|
|
981
|
-
return removeListener;
|
|
982
|
-
});
|
|
983
987
|
return new Promise((resolve, reject) => {
|
|
984
988
|
const timeout = (message) => {
|
|
985
989
|
const k = keys ? keys.join(", ") : "any";
|
|
@@ -1044,34 +1048,47 @@ class Model {
|
|
|
1044
1048
|
on(arg1, arg2, arg3) {
|
|
1045
1049
|
if (typeof arg1 == "function")
|
|
1046
1050
|
return createEffect(this.is, arg1, arg2);
|
|
1047
|
-
|
|
1051
|
+
if (typeof arg2 != "function")
|
|
1052
|
+
return awaitUpdate(this.is, arg1, arg2);
|
|
1053
|
+
if (arg1)
|
|
1054
|
+
return addEventListener(this.is, arg1, arg2, arg3);
|
|
1048
1055
|
}
|
|
1049
|
-
|
|
1056
|
+
get(arg1, arg2) {
|
|
1050
1057
|
const { state } = Control.for(this);
|
|
1051
|
-
const
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1058
|
+
const extract = typeof arg1 == "string"
|
|
1059
|
+
? () => state.get(arg1)
|
|
1060
|
+
: () => {
|
|
1061
|
+
const output = {};
|
|
1062
|
+
for (const key of arg1 || state.keys())
|
|
1063
|
+
output[key] = state.get(key);
|
|
1064
|
+
return output;
|
|
1065
|
+
};
|
|
1066
|
+
if (!arg1 || arg2 === undefined)
|
|
1067
|
+
return extract();
|
|
1068
|
+
if (typeof arg2 == "function")
|
|
1069
|
+
return this.on(arg1, () => arg2(extract()));
|
|
1070
|
+
const timeout = typeof arg2 == "number" ? arg2 : undefined;
|
|
1071
|
+
return this.on(arg1, timeout).then(extract);
|
|
1056
1072
|
}
|
|
1057
|
-
|
|
1073
|
+
set(arg1, arg2) {
|
|
1058
1074
|
const control = Control.for(this);
|
|
1059
|
-
if (typeof arg1 == "object")
|
|
1060
|
-
for (const key in arg1)
|
|
1075
|
+
if (typeof arg1 == "object")
|
|
1076
|
+
for (const key in arg1) {
|
|
1061
1077
|
if (arg2 === true || (arg2 ? arg2.includes(key) : control.state.has(key))) {
|
|
1062
1078
|
control.state.set(key, arg1[key]);
|
|
1063
1079
|
control.update(key);
|
|
1064
1080
|
}
|
|
1065
|
-
|
|
1081
|
+
}
|
|
1066
1082
|
else if (typeof arg1 == "string") {
|
|
1067
1083
|
control.update(arg1);
|
|
1068
|
-
if (1 in arguments
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1084
|
+
if (1 in arguments) {
|
|
1085
|
+
if (control.state.has(arg1))
|
|
1086
|
+
control.state.set(arg1, arg2);
|
|
1087
|
+
else if (arg1 in this) {
|
|
1088
|
+
const method = this[arg1];
|
|
1089
|
+
if (typeof method == "function")
|
|
1072
1090
|
method.call(this, arg2);
|
|
1073
|
-
|
|
1074
|
-
method.call(this);
|
|
1091
|
+
}
|
|
1075
1092
|
}
|
|
1076
1093
|
}
|
|
1077
1094
|
return {
|
|
@@ -1085,7 +1102,7 @@ class Model {
|
|
|
1085
1102
|
/**
|
|
1086
1103
|
* Clean up side effects and mark this instance for garbage-collection.
|
|
1087
1104
|
*/
|
|
1088
|
-
|
|
1105
|
+
end() {
|
|
1089
1106
|
Control.for(this).clear();
|
|
1090
1107
|
}
|
|
1091
1108
|
/**
|
|
@@ -1124,9 +1141,7 @@ class Lookup {
|
|
|
1124
1141
|
this.table = new Map();
|
|
1125
1142
|
}
|
|
1126
1143
|
get local() {
|
|
1127
|
-
return [
|
|
1128
|
-
...new Set(getOwnPropertySymbols(this).map(symbol => this[symbol]))
|
|
1129
|
-
];
|
|
1144
|
+
return unique(getOwnPropertySymbols(this).map(symbol => this[symbol]));
|
|
1130
1145
|
}
|
|
1131
1146
|
key(T) {
|
|
1132
1147
|
let key = this.table.get(T);
|
|
@@ -1139,10 +1154,7 @@ class Lookup {
|
|
|
1139
1154
|
get(T) {
|
|
1140
1155
|
return this[this.key(T)];
|
|
1141
1156
|
}
|
|
1142
|
-
|
|
1143
|
-
return create(this);
|
|
1144
|
-
}
|
|
1145
|
-
inject(T, I, writable) {
|
|
1157
|
+
add(T, I, writable) {
|
|
1146
1158
|
do {
|
|
1147
1159
|
const key = this.key(T);
|
|
1148
1160
|
const conflict = this.hasOwnProperty(key);
|
|
@@ -1154,6 +1166,9 @@ class Lookup {
|
|
|
1154
1166
|
T = getPrototypeOf(T);
|
|
1155
1167
|
} while (T !== Model);
|
|
1156
1168
|
}
|
|
1169
|
+
push() {
|
|
1170
|
+
return create(this);
|
|
1171
|
+
}
|
|
1157
1172
|
pop() {
|
|
1158
1173
|
const items = new Set();
|
|
1159
1174
|
for (const key of getOwnPropertySymbols(this)) {
|
|
@@ -1162,40 +1177,33 @@ class Lookup {
|
|
|
1162
1177
|
items.add(entry.value);
|
|
1163
1178
|
}
|
|
1164
1179
|
for (const model of items)
|
|
1165
|
-
model.
|
|
1180
|
+
model.end();
|
|
1166
1181
|
}
|
|
1167
1182
|
}
|
|
1168
1183
|
const LookupContext = React__default["default"].createContext(new Lookup());
|
|
1169
1184
|
const useLookup = () => React__default["default"].useContext(LookupContext);
|
|
1170
|
-
function useContext(Type,
|
|
1185
|
+
function useContext(Type, required) {
|
|
1171
1186
|
const instance = useLookup().get(Type);
|
|
1172
|
-
if (!instance &&
|
|
1187
|
+
if (!instance && required !== false)
|
|
1173
1188
|
throw Oops$4.NotFound(Type.name);
|
|
1174
|
-
|
|
1175
|
-
case "string":
|
|
1176
|
-
return instance[arg];
|
|
1177
|
-
case "function":
|
|
1178
|
-
React__default["default"].useLayoutEffect(() => arg(instance), []);
|
|
1179
|
-
default:
|
|
1180
|
-
return instance;
|
|
1181
|
-
}
|
|
1189
|
+
return instance;
|
|
1182
1190
|
}
|
|
1183
1191
|
|
|
1184
1192
|
const Oops$3 = issues({
|
|
1185
1193
|
NotAllowed: (parent, child) => `Global '${parent}' attempted to attach '${child}' but it is not also a singleton.`,
|
|
1186
1194
|
AmbientRequired: (requested, requester, key) => `Attempted to find an instance of ${requested} in context. It is required for [${requester}.${key}], but one could not be found.`
|
|
1187
1195
|
});
|
|
1188
|
-
const
|
|
1189
|
-
const
|
|
1196
|
+
const Pending = new WeakMap();
|
|
1197
|
+
const Applied = new WeakMap();
|
|
1190
1198
|
function tap(type, argument) {
|
|
1191
1199
|
return add(function tap(key) {
|
|
1192
|
-
if (
|
|
1200
|
+
if (type.global)
|
|
1193
1201
|
return {
|
|
1194
1202
|
recursive: true,
|
|
1195
1203
|
value: type.get()
|
|
1196
1204
|
};
|
|
1197
1205
|
const { subject } = this;
|
|
1198
|
-
if (
|
|
1206
|
+
if (subject.constructor.global)
|
|
1199
1207
|
throw Oops$3.NotAllowed(subject, type.name);
|
|
1200
1208
|
getPending(subject).push(context => {
|
|
1201
1209
|
let instance = context.get(type);
|
|
@@ -1215,24 +1223,24 @@ function tap(type, argument) {
|
|
|
1215
1223
|
});
|
|
1216
1224
|
}
|
|
1217
1225
|
function usePeerContext(subject) {
|
|
1218
|
-
if (
|
|
1219
|
-
if (
|
|
1226
|
+
if (Applied.has(subject)) {
|
|
1227
|
+
if (Applied.get(subject))
|
|
1220
1228
|
useLookup();
|
|
1221
1229
|
return;
|
|
1222
1230
|
}
|
|
1223
|
-
const pending =
|
|
1231
|
+
const pending = Pending.get(subject);
|
|
1224
1232
|
if (pending) {
|
|
1225
1233
|
const local = useLookup();
|
|
1226
1234
|
for (const init of pending)
|
|
1227
1235
|
init(local);
|
|
1228
|
-
|
|
1236
|
+
Pending.delete(subject);
|
|
1229
1237
|
}
|
|
1230
|
-
|
|
1238
|
+
Applied.set(subject, !!pending);
|
|
1231
1239
|
}
|
|
1232
1240
|
function getPending(subject) {
|
|
1233
|
-
let pending =
|
|
1241
|
+
let pending = Pending.get(subject);
|
|
1234
1242
|
if (!pending)
|
|
1235
|
-
|
|
1243
|
+
Pending.set(subject, pending = []);
|
|
1236
1244
|
return pending;
|
|
1237
1245
|
}
|
|
1238
1246
|
|
|
@@ -1243,9 +1251,9 @@ function use(init) {
|
|
|
1243
1251
|
return state[0];
|
|
1244
1252
|
}
|
|
1245
1253
|
|
|
1246
|
-
function
|
|
1254
|
+
function useNew(source, arg1, arg2) {
|
|
1247
1255
|
const instance = React__default["default"].useMemo(() => {
|
|
1248
|
-
const callback = arg2 ||
|
|
1256
|
+
const callback = arg2 || arg1;
|
|
1249
1257
|
const instance = Model.isTypeof(source) ?
|
|
1250
1258
|
source.new() :
|
|
1251
1259
|
source();
|
|
@@ -1255,27 +1263,27 @@ function useModel(source, arg, arg2) {
|
|
|
1255
1263
|
return instance;
|
|
1256
1264
|
}, []);
|
|
1257
1265
|
usePeerContext(instance);
|
|
1258
|
-
if (Array.isArray(
|
|
1266
|
+
if (Array.isArray(arg1)) {
|
|
1259
1267
|
const update = React.useState(0)[1];
|
|
1260
1268
|
React__default["default"].useLayoutEffect(() => {
|
|
1261
|
-
if (
|
|
1262
|
-
instance.on(
|
|
1269
|
+
if (arg1.length && instance instanceof Model)
|
|
1270
|
+
instance.on(arg1, () => update(x => x + 1));
|
|
1263
1271
|
return () => {
|
|
1264
1272
|
if (Model.isTypeof(source))
|
|
1265
|
-
instance.
|
|
1273
|
+
instance.end();
|
|
1266
1274
|
};
|
|
1267
1275
|
}, []);
|
|
1268
1276
|
return instance;
|
|
1269
1277
|
}
|
|
1270
1278
|
const local = use(refresh => (Control.for(instance).subscribe(() => refresh)));
|
|
1271
|
-
if (typeof
|
|
1272
|
-
local.assign(
|
|
1279
|
+
if (typeof arg1 == "object")
|
|
1280
|
+
local.assign(arg1, arg2);
|
|
1273
1281
|
React__default["default"].useLayoutEffect(() => {
|
|
1274
1282
|
local.commit();
|
|
1275
1283
|
return () => {
|
|
1276
1284
|
local.release();
|
|
1277
1285
|
if (Model.isTypeof(source))
|
|
1278
|
-
instance.
|
|
1286
|
+
instance.end();
|
|
1279
1287
|
};
|
|
1280
1288
|
}, []);
|
|
1281
1289
|
return local.proxy;
|
|
@@ -1324,9 +1332,11 @@ function useValue(source, compute, suspend) {
|
|
|
1324
1332
|
}
|
|
1325
1333
|
defineProperty(sub, "proxy", {
|
|
1326
1334
|
get() {
|
|
1327
|
-
if (value
|
|
1335
|
+
if (value !== undefined)
|
|
1336
|
+
return value;
|
|
1337
|
+
if (suspend)
|
|
1328
1338
|
throw new Promise(res => retry = res);
|
|
1329
|
-
return
|
|
1339
|
+
return null;
|
|
1330
1340
|
}
|
|
1331
1341
|
});
|
|
1332
1342
|
return sub;
|
|
@@ -1341,7 +1351,7 @@ function useTap(source, arg1, arg2) {
|
|
|
1341
1351
|
return () => source;
|
|
1342
1352
|
if (Model.isTypeof(source))
|
|
1343
1353
|
return "get" in source
|
|
1344
|
-
? () => source.get(
|
|
1354
|
+
? () => source.get()
|
|
1345
1355
|
: () => useContext(source);
|
|
1346
1356
|
return source;
|
|
1347
1357
|
}, [])();
|
|
@@ -1357,22 +1367,72 @@ function useTap(source, arg1, arg2) {
|
|
|
1357
1367
|
return value;
|
|
1358
1368
|
}
|
|
1359
1369
|
|
|
1370
|
+
const Global$1 = new WeakMap();
|
|
1371
|
+
const Oops$2 = issues({
|
|
1372
|
+
DoesNotExist: (name) => `Tried to access singleton ${name}, but none exist! Did you forget to initialize?\nCall ${name}.new() before attempting to access, or consider using ${name}.use() instead.`,
|
|
1373
|
+
AlreadyExists: (name) => `Shared instance of ${name} already exists! Consider unmounting existing, or use ${name}.reset() to force-delete it.`
|
|
1374
|
+
});
|
|
1360
1375
|
class MVC extends Model {
|
|
1361
|
-
|
|
1362
|
-
|
|
1376
|
+
end(force) {
|
|
1377
|
+
const type = this.constructor;
|
|
1378
|
+
if (type.keepAlive && !force)
|
|
1379
|
+
return false;
|
|
1380
|
+
super.end();
|
|
1381
|
+
Global$1.delete(type);
|
|
1382
|
+
return true;
|
|
1383
|
+
}
|
|
1384
|
+
static new(...args) {
|
|
1385
|
+
if (Global$1.has(this))
|
|
1386
|
+
if (this.keepAlive)
|
|
1387
|
+
return Global$1.get(this);
|
|
1388
|
+
else
|
|
1389
|
+
throw Oops$2.AlreadyExists(this.name);
|
|
1390
|
+
const instance = super.new(...args);
|
|
1391
|
+
if (this.global)
|
|
1392
|
+
Global$1.set(this, instance);
|
|
1393
|
+
return instance;
|
|
1394
|
+
}
|
|
1395
|
+
static get(arg1, arg2) {
|
|
1396
|
+
let instance;
|
|
1397
|
+
const required = arg1 === undefined || arg1 === true;
|
|
1398
|
+
if (this.global) {
|
|
1399
|
+
instance = Global$1.get(this);
|
|
1400
|
+
if (!instance && required)
|
|
1401
|
+
throw Oops$2.DoesNotExist(this.name);
|
|
1402
|
+
}
|
|
1403
|
+
else
|
|
1404
|
+
instance = useContext(this, required);
|
|
1405
|
+
function callback(effect) {
|
|
1406
|
+
try {
|
|
1407
|
+
React__default["default"].useLayoutEffect(() => effect(instance), []);
|
|
1408
|
+
}
|
|
1409
|
+
catch (err) {
|
|
1410
|
+
if (instance)
|
|
1411
|
+
instance.on(effect, []);
|
|
1412
|
+
else
|
|
1413
|
+
effect(undefined);
|
|
1414
|
+
}
|
|
1415
|
+
}
|
|
1416
|
+
if (typeof arg1 === "string")
|
|
1417
|
+
return instance[arg1];
|
|
1418
|
+
if (typeof arg1 === "function" && instance)
|
|
1419
|
+
callback(arg1);
|
|
1420
|
+
else if (arg2)
|
|
1421
|
+
callback(arg2);
|
|
1422
|
+
return instance;
|
|
1363
1423
|
}
|
|
1364
1424
|
static tap(key, expect) {
|
|
1365
1425
|
return useTap(this, key, expect);
|
|
1366
1426
|
}
|
|
1367
1427
|
static use(a, b) {
|
|
1368
|
-
return
|
|
1428
|
+
return useNew(this, a, b);
|
|
1369
1429
|
}
|
|
1370
1430
|
static meta(path, expect) {
|
|
1371
1431
|
return useTap(() => this, path, expect);
|
|
1372
1432
|
}
|
|
1373
1433
|
}
|
|
1374
1434
|
|
|
1375
|
-
const Oops$
|
|
1435
|
+
const Oops$1 = issues({
|
|
1376
1436
|
BadProps: () => `Provider expects either a render function, 'get' or 'has' props.`
|
|
1377
1437
|
});
|
|
1378
1438
|
function Consumer(props) {
|
|
@@ -1383,58 +1443,50 @@ function Consumer(props) {
|
|
|
1383
1443
|
if (typeof callback == "function")
|
|
1384
1444
|
callback(useContext(type, !!has));
|
|
1385
1445
|
else
|
|
1386
|
-
throw Oops$
|
|
1446
|
+
throw Oops$1.BadProps();
|
|
1387
1447
|
return null;
|
|
1388
1448
|
}
|
|
1389
1449
|
|
|
1390
|
-
const Oops
|
|
1450
|
+
const Oops = issues({
|
|
1391
1451
|
NoType: () => "Provider 'for' prop must be Model, typeof Model or a collection of them."
|
|
1392
1452
|
});
|
|
1393
1453
|
function Provider(props) {
|
|
1394
|
-
const context = useNewContext(props.for);
|
|
1454
|
+
const context = useNewContext(props.for, props.and);
|
|
1395
1455
|
const render = props.children;
|
|
1396
|
-
useAppliedProps(context, props);
|
|
1397
1456
|
React__default["default"].useLayoutEffect(() => () => context.pop(), []);
|
|
1398
1457
|
return React__default["default"].createElement(LookupContext.Provider, { value: context }, typeof render == "function"
|
|
1399
1458
|
? React__default["default"].createElement(RenderFunction, { context, render })
|
|
1400
1459
|
: render);
|
|
1401
1460
|
}
|
|
1402
|
-
function useNewContext(include) {
|
|
1461
|
+
function useNewContext(include, assign) {
|
|
1403
1462
|
const ambient = useLookup();
|
|
1404
|
-
|
|
1463
|
+
const context = React__default["default"].useMemo(() => {
|
|
1405
1464
|
if (!include)
|
|
1406
|
-
throw Oops
|
|
1407
|
-
const
|
|
1465
|
+
throw Oops.NoType();
|
|
1466
|
+
const next = ambient.push();
|
|
1408
1467
|
function register(I) {
|
|
1409
1468
|
if (I instanceof Model)
|
|
1410
|
-
|
|
1469
|
+
next.add(I.constructor, I, false);
|
|
1411
1470
|
else
|
|
1412
|
-
|
|
1471
|
+
next.add(I, I.new(), true);
|
|
1413
1472
|
}
|
|
1414
1473
|
if (include instanceof Model || typeof include == "function")
|
|
1415
1474
|
register(include);
|
|
1416
1475
|
else
|
|
1417
1476
|
values(include).forEach(register);
|
|
1418
|
-
for (const instance of
|
|
1477
|
+
for (const instance of next.local)
|
|
1419
1478
|
if (instance)
|
|
1420
1479
|
for (const apply of getPending(instance))
|
|
1421
|
-
apply(
|
|
1422
|
-
return
|
|
1423
|
-
}, []);
|
|
1424
|
-
}
|
|
1425
|
-
function useAppliedProps(context, props) {
|
|
1426
|
-
const apply = React__default["default"].useMemo(() => {
|
|
1427
|
-
return (props) => {
|
|
1428
|
-
entries(props).forEach(([key, value]) => {
|
|
1429
|
-
if (key == "for" || key == "children")
|
|
1430
|
-
return;
|
|
1431
|
-
for (const into of context.local)
|
|
1432
|
-
if (into && key in into)
|
|
1433
|
-
into[key] = value;
|
|
1434
|
-
});
|
|
1435
|
-
};
|
|
1480
|
+
apply(next);
|
|
1481
|
+
return next;
|
|
1436
1482
|
}, []);
|
|
1437
|
-
|
|
1483
|
+
if (assign) {
|
|
1484
|
+
for (const key in assign)
|
|
1485
|
+
for (const into of context.local)
|
|
1486
|
+
if (into && key in into)
|
|
1487
|
+
into[key] = assign[key];
|
|
1488
|
+
}
|
|
1489
|
+
return context;
|
|
1438
1490
|
}
|
|
1439
1491
|
function RenderFunction(props) {
|
|
1440
1492
|
const hook = use(refresh => {
|
|
@@ -1448,57 +1500,9 @@ function RenderFunction(props) {
|
|
|
1448
1500
|
return props.render(hook.proxy);
|
|
1449
1501
|
}
|
|
1450
1502
|
|
|
1451
|
-
const Oops = issues({
|
|
1452
|
-
DoesNotExist: (name) => `Tried to access singleton ${name}, but none exist! Did you forget to initialize?\nCall ${name}.new() before attempting to access, or consider using ${name}.use() instead.`,
|
|
1453
|
-
AlreadyExists: (name) => `Shared instance of ${name} already exists! Consider unmounting existing, or use ${name}.reset() to force-delete it.`
|
|
1454
|
-
});
|
|
1455
|
-
const Active = new WeakMap();
|
|
1456
1503
|
class Global extends MVC {
|
|
1457
|
-
constructor() {
|
|
1458
|
-
super();
|
|
1459
|
-
Active.set(this.constructor, this);
|
|
1460
|
-
}
|
|
1461
|
-
destroy(force) {
|
|
1462
|
-
const type = this.constructor;
|
|
1463
|
-
if (type.keepAlive && !force)
|
|
1464
|
-
return false;
|
|
1465
|
-
Control.for(this).clear();
|
|
1466
|
-
Active.delete(type);
|
|
1467
|
-
return true;
|
|
1468
|
-
}
|
|
1469
|
-
static new(...args) {
|
|
1470
|
-
if (Active.has(this))
|
|
1471
|
-
if (this.keepAlive)
|
|
1472
|
-
return Active.get(this);
|
|
1473
|
-
else
|
|
1474
|
-
throw Oops.AlreadyExists(this.name);
|
|
1475
|
-
const instance = new this(...args);
|
|
1476
|
-
Control.for(instance);
|
|
1477
|
-
return instance;
|
|
1478
|
-
}
|
|
1479
|
-
/**
|
|
1480
|
-
* Update the active instance of this class.
|
|
1481
|
-
* Returns a thenable; resolves after successful update.
|
|
1482
|
-
* If instance does not already exist, one will be created.
|
|
1483
|
-
*/
|
|
1484
|
-
static set(values) {
|
|
1485
|
-
return this.get(true).update(values);
|
|
1486
|
-
}
|
|
1487
|
-
static get(arg) {
|
|
1488
|
-
const instance = Active.get(this);
|
|
1489
|
-
if (!instance && arg !== false)
|
|
1490
|
-
throw Oops.DoesNotExist(this.name);
|
|
1491
|
-
return (typeof arg == "string" ?
|
|
1492
|
-
instance[arg] :
|
|
1493
|
-
instance);
|
|
1494
|
-
}
|
|
1495
|
-
/** Destroy current instance of Global, if it exists. */
|
|
1496
|
-
static reset() {
|
|
1497
|
-
const current = Active.get(this);
|
|
1498
|
-
if (current)
|
|
1499
|
-
current.destroy(true);
|
|
1500
|
-
}
|
|
1501
1504
|
}
|
|
1505
|
+
Global.global = true;
|
|
1502
1506
|
Global.keepAlive = true;
|
|
1503
1507
|
|
|
1504
1508
|
const LOCAL = "$debug local";
|
|
@@ -1554,7 +1558,6 @@ exports.set = set;
|
|
|
1554
1558
|
exports.tap = tap;
|
|
1555
1559
|
exports.use = use$1;
|
|
1556
1560
|
exports.useContext = useContext;
|
|
1557
|
-
exports.
|
|
1561
|
+
exports.useNew = useNew;
|
|
1558
1562
|
exports.useTap = useTap;
|
|
1559
|
-
exports.useValue = useValue;
|
|
1560
1563
|
//# sourceMappingURL=index.js.map
|