nfkit 1.0.33 → 1.0.34
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 +42 -17
- package/dist/index.cjs.map +2 -2
- package/dist/index.mjs +42 -17
- package/dist/index.mjs.map +2 -2
- package/dist/src/app-context/app-context.d.ts +4 -0
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1254,6 +1254,7 @@ var AppContextCore = class {
|
|
|
1254
1254
|
this.provideRecords = [];
|
|
1255
1255
|
this.registry = /* @__PURE__ */ new Map();
|
|
1256
1256
|
this.objectSteps = [];
|
|
1257
|
+
this.parentContexts = /* @__PURE__ */ new Set();
|
|
1257
1258
|
this.started = false;
|
|
1258
1259
|
this.starting = false;
|
|
1259
1260
|
this.startingEntries = null;
|
|
@@ -1295,6 +1296,43 @@ var AppContextCore = class {
|
|
|
1295
1296
|
this.loadingRecords.delete(record);
|
|
1296
1297
|
}
|
|
1297
1298
|
}
|
|
1299
|
+
applyUsedContext(other) {
|
|
1300
|
+
if (Array.isArray(other?.provideRecords)) {
|
|
1301
|
+
this.provideRecords.push(...other.provideRecords);
|
|
1302
|
+
}
|
|
1303
|
+
if (Array.isArray(other?.objectSteps)) {
|
|
1304
|
+
this.objectSteps.push(...other.objectSteps);
|
|
1305
|
+
for (const step of other.objectSteps) {
|
|
1306
|
+
step(this);
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
if (other?.started) {
|
|
1310
|
+
if (other?.registry instanceof Map) {
|
|
1311
|
+
for (const [key, value] of other.registry.entries()) {
|
|
1312
|
+
this.registry.set(key, value);
|
|
1313
|
+
}
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1317
|
+
hasStartedInParentChain(visited = /* @__PURE__ */ new Set()) {
|
|
1318
|
+
if (visited.has(this)) return false;
|
|
1319
|
+
visited.add(this);
|
|
1320
|
+
if (this.started) return true;
|
|
1321
|
+
for (const parent of this.parentContexts) {
|
|
1322
|
+
if (parent.hasStartedInParentChain(visited)) {
|
|
1323
|
+
return true;
|
|
1324
|
+
}
|
|
1325
|
+
}
|
|
1326
|
+
return false;
|
|
1327
|
+
}
|
|
1328
|
+
propagateUsedContextToParents(other, visited = /* @__PURE__ */ new Set()) {
|
|
1329
|
+
if (visited.has(this)) return;
|
|
1330
|
+
visited.add(this);
|
|
1331
|
+
for (const parent of this.parentContexts) {
|
|
1332
|
+
parent.applyUsedContext(other);
|
|
1333
|
+
parent.propagateUsedContextToParents(other, visited);
|
|
1334
|
+
}
|
|
1335
|
+
}
|
|
1298
1336
|
provide(cls, ...args) {
|
|
1299
1337
|
const last = args[args.length - 1];
|
|
1300
1338
|
const hasOptions = !!last && typeof last === "object" && ("provide" in last || "merge" in last || "useValue" in last || "useFactory" in last || "useClass" in last);
|
|
@@ -1385,27 +1423,14 @@ var AppContextCore = class {
|
|
|
1385
1423
|
use(...ctxes) {
|
|
1386
1424
|
for (const ctx of ctxes) {
|
|
1387
1425
|
const other = ctx;
|
|
1388
|
-
if (this.
|
|
1426
|
+
if (this.hasStartedInParentChain() && !other?.started) {
|
|
1389
1427
|
throw new Error(
|
|
1390
1428
|
"Cannot use an unstarted context into a started context."
|
|
1391
1429
|
);
|
|
1392
1430
|
}
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
if (Array.isArray(other?.objectSteps)) {
|
|
1397
|
-
this.objectSteps.push(...other.objectSteps);
|
|
1398
|
-
for (const step of other.objectSteps) {
|
|
1399
|
-
step(this);
|
|
1400
|
-
}
|
|
1401
|
-
}
|
|
1402
|
-
if (other?.started) {
|
|
1403
|
-
if (other?.registry instanceof Map) {
|
|
1404
|
-
for (const [key, value] of other.registry.entries()) {
|
|
1405
|
-
this.registry.set(key, value);
|
|
1406
|
-
}
|
|
1407
|
-
}
|
|
1408
|
-
}
|
|
1431
|
+
this.applyUsedContext(other);
|
|
1432
|
+
other.parentContexts.add(this);
|
|
1433
|
+
this.propagateUsedContextToParents(other);
|
|
1409
1434
|
}
|
|
1410
1435
|
return this;
|
|
1411
1436
|
}
|