nfkit 1.0.30 → 1.0.31
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.cjs
CHANGED
|
@@ -1302,6 +1302,7 @@ var AppContextCore = class {
|
|
|
1302
1302
|
this.provideRecords = [];
|
|
1303
1303
|
this.registry = /* @__PURE__ */ new Map();
|
|
1304
1304
|
this.objectSteps = [];
|
|
1305
|
+
this.parentContexts = /* @__PURE__ */ new Set();
|
|
1305
1306
|
this.started = false;
|
|
1306
1307
|
this.starting = false;
|
|
1307
1308
|
this.startingEntries = null;
|
|
@@ -1343,6 +1344,43 @@ var AppContextCore = class {
|
|
|
1343
1344
|
this.loadingRecords.delete(record);
|
|
1344
1345
|
}
|
|
1345
1346
|
}
|
|
1347
|
+
applyUsedContext(other) {
|
|
1348
|
+
if (Array.isArray(other?.provideRecords)) {
|
|
1349
|
+
this.provideRecords.push(...other.provideRecords);
|
|
1350
|
+
}
|
|
1351
|
+
if (Array.isArray(other?.objectSteps)) {
|
|
1352
|
+
this.objectSteps.push(...other.objectSteps);
|
|
1353
|
+
for (const step of other.objectSteps) {
|
|
1354
|
+
step(this);
|
|
1355
|
+
}
|
|
1356
|
+
}
|
|
1357
|
+
if (other?.started) {
|
|
1358
|
+
if (other?.registry instanceof Map) {
|
|
1359
|
+
for (const [key, value] of other.registry.entries()) {
|
|
1360
|
+
this.registry.set(key, value);
|
|
1361
|
+
}
|
|
1362
|
+
}
|
|
1363
|
+
}
|
|
1364
|
+
}
|
|
1365
|
+
hasStartedInParentChain(visited = /* @__PURE__ */ new Set()) {
|
|
1366
|
+
if (visited.has(this)) return false;
|
|
1367
|
+
visited.add(this);
|
|
1368
|
+
if (this.started) return true;
|
|
1369
|
+
for (const parent of this.parentContexts) {
|
|
1370
|
+
if (parent.hasStartedInParentChain(visited)) {
|
|
1371
|
+
return true;
|
|
1372
|
+
}
|
|
1373
|
+
}
|
|
1374
|
+
return false;
|
|
1375
|
+
}
|
|
1376
|
+
propagateUsedContextToParents(other, visited = /* @__PURE__ */ new Set()) {
|
|
1377
|
+
if (visited.has(this)) return;
|
|
1378
|
+
visited.add(this);
|
|
1379
|
+
for (const parent of this.parentContexts) {
|
|
1380
|
+
parent.applyUsedContext(other);
|
|
1381
|
+
parent.propagateUsedContextToParents(other, visited);
|
|
1382
|
+
}
|
|
1383
|
+
}
|
|
1346
1384
|
provide(cls, ...args) {
|
|
1347
1385
|
const last = args[args.length - 1];
|
|
1348
1386
|
const hasOptions = !!last && typeof last === "object" && ("provide" in last || "merge" in last || "useValue" in last || "useFactory" in last || "useClass" in last);
|
|
@@ -1433,27 +1471,14 @@ var AppContextCore = class {
|
|
|
1433
1471
|
use(...ctxes) {
|
|
1434
1472
|
for (const ctx of ctxes) {
|
|
1435
1473
|
const other = ctx;
|
|
1436
|
-
if (this.
|
|
1474
|
+
if (this.hasStartedInParentChain() && !other?.started) {
|
|
1437
1475
|
throw new Error(
|
|
1438
1476
|
"Cannot use an unstarted context into a started context."
|
|
1439
1477
|
);
|
|
1440
1478
|
}
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
if (Array.isArray(other?.objectSteps)) {
|
|
1445
|
-
this.objectSteps.push(...other.objectSteps);
|
|
1446
|
-
for (const step of other.objectSteps) {
|
|
1447
|
-
step(this);
|
|
1448
|
-
}
|
|
1449
|
-
}
|
|
1450
|
-
if (other?.started) {
|
|
1451
|
-
if (other?.registry instanceof Map) {
|
|
1452
|
-
for (const [key, value] of other.registry.entries()) {
|
|
1453
|
-
this.registry.set(key, value);
|
|
1454
|
-
}
|
|
1455
|
-
}
|
|
1456
|
-
}
|
|
1479
|
+
this.applyUsedContext(other);
|
|
1480
|
+
other.parentContexts.add(this);
|
|
1481
|
+
this.propagateUsedContextToParents(other);
|
|
1457
1482
|
}
|
|
1458
1483
|
return this;
|
|
1459
1484
|
}
|