Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
N
nfkit
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nanahira
nfkit
Commits
e7283a63
Commit
e7283a63
authored
Feb 17, 2026
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "Reapply "fix""
This reverts commit
312241b5
.
parent
a2be3607
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
73 deletions
+23
-73
src/app-context/app-context.ts
src/app-context/app-context.ts
+23
-56
tests/app-context.spec.ts
tests/app-context.spec.ts
+0
-17
No files found.
src/app-context/app-context.ts
View file @
e7283a63
...
@@ -40,7 +40,6 @@ export class AppContextCore<Cur = Empty, Req = Empty> {
...
@@ -40,7 +40,6 @@ export class AppContextCore<Cur = Empty, Req = Empty> {
private
provideRecords
:
ProvideRecord
[]
=
[];
private
provideRecords
:
ProvideRecord
[]
=
[];
private
registry
=
new
Map
<
string
|
AnyClass
,
LoadEntry
>
();
private
registry
=
new
Map
<
string
|
AnyClass
,
LoadEntry
>
();
private
objectSteps
:
ObjectStep
[]
=
[];
private
objectSteps
:
ObjectStep
[]
=
[];
private
parentContexts
=
new
Set
<
AppContextCore
<
any
,
any
>>
();
started
=
false
;
started
=
false
;
private
starting
=
false
;
private
starting
=
false
;
private
startingEntries
:
LoadEntry
[]
|
null
=
null
;
private
startingEntries
:
LoadEntry
[]
|
null
=
null
;
...
@@ -89,57 +88,6 @@ export class AppContextCore<Cur = Empty, Req = Empty> {
...
@@ -89,57 +88,6 @@ export class AppContextCore<Cur = Empty, Req = Empty> {
}
}
}
}
private applyUsedContext(other: AppContextCore<any, any>) {
// Copy provide records
if (Array.isArray(other?.provideRecords)) {
this.provideRecords.push(...other.provideRecords);
}
// Copy and apply object steps
if (Array.isArray(other?.objectSteps)) {
this.objectSteps.push(...other.objectSteps);
for (const step of other.objectSteps) {
step(this);
}
}
// If the other context has already started, copy loaded entries only.
// They should remain initialized by the source context and must not be re-initialized.
if (other?.started) {
if (other?.registry instanceof Map) {
for (const [key, value] of other.registry.entries()) {
this.registry.set(key, value);
}
}
}
}
private hasStartedInParentChain(
visited = new Set<AppContextCore<any, any>>(),
): boolean {
if (visited.has(this)) return false;
visited.add(this);
if (this.started) return true;
for (const parent of this.parentContexts) {
if (parent.hasStartedInParentChain(visited)) {
return true;
}
}
return false;
}
private propagateUsedContextToParents(
other: AppContextCore<any, any>,
visited = new Set<AppContextCore<any, any>>(),
) {
if (visited.has(this)) return;
visited.add(this);
for (const parent of this.parentContexts) {
parent.applyUsedContext(other);
parent.propagateUsedContextToParents(other, visited);
}
}
provide<
provide<
C extends AppServiceClass<Cur, Req>,
C extends AppServiceClass<Cur, Req>,
const P extends string = '',
const P extends string = '',
...
@@ -286,15 +234,34 @@ export class AppContextCore<Cur = Empty, Req = Empty> {
...
@@ -286,15 +234,34 @@ export class AppContextCore<Cur = Empty, Req = Empty> {
for (const ctx of ctxes) {
for (const ctx of ctxes) {
const other = ctx as any as AppContextCore<any, any>;
const other = ctx as any as AppContextCore<any, any>;
if (this.
hasStartedInParentChain()
&& !other?.started) {
if (this.
started
&& !other?.started) {
throw new Error(
throw new Error(
'Cannot use an unstarted context into a started context.',
'Cannot use an unstarted context into a started context.',
);
);
}
}
this.applyUsedContext(other);
// Copy provide records
other.parentContexts.add(this);
if (Array.isArray(other?.provideRecords)) {
this.propagateUsedContextToParents(other);
this.provideRecords.push(...other.provideRecords);
}
// Copy and apply object steps
if (Array.isArray(other?.objectSteps)) {
this.objectSteps.push(...other.objectSteps);
for (const step of other.objectSteps) {
step(this);
}
}
// If the other context has already started, copy loaded entries only.
// They should remain initialized by the source context and must not be re-initialized.
if (other?.started) {
if (other?.registry instanceof Map) {
for (const [key, value] of other.registry.entries()) {
this.registry.set(key, value);
}
}
}
}
}
return this as any;
return this as any;
...
...
tests/app-context.spec.ts
View file @
e7283a63
...
@@ -226,23 +226,6 @@ describe('app-context runtime', () => {
...
@@ -226,23 +226,6 @@ describe('app-context runtime', () => {
expect
(
root
.
needsCounter
.
counter
).
toBe
(
root
.
counter
);
expect
(
root
.
needsCounter
.
counter
).
toBe
(
root
.
counter
);
expect
(
root
.
needsCounter
.
counter
.
value
).
toBe
(
34
);
expect
(
root
.
needsCounter
.
counter
.
value
).
toBe
(
34
);
});
});
test
(
'
late b.use(c) propagates to a and c can access providers from a
'
,
async
()
=>
{
const
p
=
createAppContext
()
.
provide
(
CounterService
,
55
,
{
provide
:
'
counter
'
})
.
define
();
const
b
=
createAppContext
().
define
();
const
a
=
createAppContext
().
use
(
p
).
use
(
b
).
define
();
const
c
=
createAppContext
()
.
provide
(
NeedsCounterService
,
{
provide
:
'
needsCounter
'
})
.
define
();
b
.
use
(
c
);
const
root
=
await
a
.
start
();
expect
((
root
as
any
).
needsCounter
.
counter
).
toBe
(
root
.
counter
);
expect
((
root
as
any
).
needsCounter
.
counter
.
value
).
toBe
(
55
);
});
});
});
describe
(
'
app-context type checks
'
,
()
=>
{
describe
(
'
app-context type checks
'
,
()
=>
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment