Skip to content

Commit

Permalink
feat: add Owner.root shallow property that stores the root owner
Browse files Browse the repository at this point in the history
The root property can be used to store referentially unique object accessible in the owner tree. This property is copied to child owners and computations.
  • Loading branch information
pedro00dk committed May 24, 2023
1 parent f99dd04 commit 1b45169
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/solid/src/reactive/signal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export interface SignalState<T> extends SourceMapValue {
}

export interface Owner {
root?: Owner;
owned: Computation<any>[] | null;
cleanups: (() => void)[] | null;
owner: Owner | null;
Expand Down Expand Up @@ -145,6 +146,7 @@ export function createRoot<T>(fn: RootFunction<T>, detachedOwner?: typeof Owner)
? { owned: null, cleanups: null, context: null, owner: null }
: UNOWNED
: {
root: detachedOwner?.root ?? owner?.root,
owned: null,
cleanups: null,
context: null,
Expand Down Expand Up @@ -1396,6 +1398,7 @@ function createComputation<Next, Init = unknown>(
sourceSlots: null,
cleanups: null,
value: init,
root: Owner?.root,
owner: Owner,
context: null,
pure
Expand Down

0 comments on commit 1b45169

Please sign in to comment.