11import { throttle } from '@solid-primitives/scheduled'
2- import * as registry from '../main/component-registry.ts'
32import { ObjectType , getSdtId } from '../main/id.ts'
43import * as roots from '../main/roots.ts'
54import { type Mapped , type NodeID , type Solid , DEFAULT_WALKER_MODE , DevtoolsMainView , NodeType , TreeWalkerMode } from '../main/types.ts'
65import { isDisposed , markOwnerType } from '../main/utils.ts'
7- import { type ComputationUpdateHandler , walkSolidTree } from './walker.ts'
6+ import * as walker from './walker.ts'
87
98export type StructureUpdates = {
109 /** Partial means that the updates are based on the previous structure state */
@@ -43,10 +42,11 @@ function getClosestIncludedOwner(owner: Solid.Owner, mode: TreeWalkerMode): Soli
4342 return root
4443}
4544
46- export function createStructure ( props : {
45+ export function createStructure < TEl extends object > ( props : {
4746 onStructureUpdate : ( updates : StructureUpdates ) => void
4847 onNodeUpdate : ( nodeId : NodeID ) => void
4948 enabled : ( ) => boolean
49+ component_registry : walker . ComponentRegistry < TEl > ,
5050} ) {
5151
5252 let treeWalkerMode : TreeWalkerMode = DEFAULT_WALKER_MODE
@@ -57,7 +57,7 @@ export function createStructure(props: {
5757 const removedRoots = new Set < NodeID > ( )
5858 let shouldUpdateAllRoots = true
5959
60- const onComputationUpdate : ComputationUpdateHandler = (
60+ const onComputationUpdate : walker . ComputationUpdateHandler = (
6161 rootId , owner , changedStructure ,
6262 ) => {
6363 // separate the callback from the computation
@@ -72,9 +72,9 @@ export function createStructure(props: {
7272 }
7373
7474 function forceFlushRootUpdateQueue ( ) : void {
75-
75+
7676 if ( props . enabled ( ) ) {
77-
77+
7878 let partial = ! shouldUpdateAllRoots
7979 shouldUpdateAllRoots = false
8080
@@ -92,16 +92,17 @@ export function createStructure(props: {
9292 }
9393
9494 for ( let owner of owners ) {
95- let rootId = getRootId ( owner )
96- let tree = walkSolidTree ( owner , {
97- rootId,
98- mode : treeWalkerMode ,
99- onComputationUpdate,
100- registerComponent : registry . registerComponent ,
95+ let root_id = getRootId ( owner )
96+ let tree = walker . walkSolidTree ( owner , {
97+ rootId : root_id ,
98+ mode : treeWalkerMode ,
99+ onUpdate : onComputationUpdate ,
100+ eli : props . component_registry . eli ,
101+ registry : props . component_registry ,
101102 } )
102- let map = updated [ rootId ]
103- if ( map ) map [ tree . id ] = tree
104- else updated [ rootId ] = { [ tree . id ] : tree }
103+ let map = updated [ root_id ]
104+ if ( map != null ) map [ tree . id ] = tree
105+ else updated [ root_id ] = { [ tree . id ] : tree }
105106 }
106107
107108 props . onStructureUpdate ( { partial, updated, removed : [ ...removedRoots ] } )
@@ -143,7 +144,7 @@ export function createStructure(props: {
143144 function setTreeWalkerMode ( mode : TreeWalkerMode ) : void {
144145 treeWalkerMode = mode
145146 updateAllRoots ( )
146- registry . clearComponentRegistry ( )
147+ walker . clearComponentRegistry ( props . component_registry )
147148 }
148149
149150 return {
0 commit comments