@@ -45,7 +45,7 @@ export interface Options extends preact.Options {
45
45
_internal ?( internal : Internal , vnode : VNode | string ) : void ;
46
46
}
47
47
48
- export type CommitQueue = Internal [ ] ;
48
+ export type CommitQueue = ComponentInternal [ ] ;
49
49
50
50
// Redefine ComponentFactory using our new internal FunctionalComponent interface above
51
51
export type ComponentFactory < P > =
@@ -130,18 +130,13 @@ export interface VNode<P = {}> extends preact.VNode<P> {
130
130
* An Internal is a persistent backing node within Preact's virtual DOM tree.
131
131
* Think of an Internal like a long-lived VNode with stored data and tree linkages.
132
132
*/
133
- export interface Internal < P = { } > {
134
- type : string | ComponentType < P > ;
135
- /** The props object for Elements/Components, and the string contents for Text */
136
- props : ( P & { children : ComponentChildren } ) | string | number ;
133
+ export interface BaseInternal < P = { } > {
137
134
key : any ;
138
135
ref : Ref < any > | null ;
139
136
_prevRef : Ref < any > | null ;
140
137
141
138
/** Bitfield containing information about the Internal or its component. */
142
139
flags : number ;
143
- /** Polymorphic property to store extensions like hooks on */
144
- data : object | PreactNode ;
145
140
/** The function that triggers in-place re-renders for an internal */
146
141
rerender : ( internal : Internal ) => void ;
147
142
@@ -159,16 +154,52 @@ export interface Internal<P = {}> {
159
154
_component : Component | null ;
160
155
/** This Internal's distance from the tree root */
161
156
_depth : number | null ;
162
- /** Callbacks to invoke when this internal commits */
163
- _commitCallbacks : Array < ( ) => void > ;
164
- _stateCallbacks : Array < ( ) => void > ; // Only class components
165
157
}
166
158
159
+ export interface ComponentInternal < P = { } > extends BaseInternal < P > {
160
+ type : ComponentType < P > ;
161
+ props : P & { children : ComponentChildren } ;
162
+ /** Polymorphic property to store extensions like hooks on */
163
+ data : {
164
+ /** Callbacks to invoke when this internal commits */
165
+ _commitCallbacks : Array < ( ) => void > ;
166
+ _stateCallbacks : Array < ( ) => void > ; // Only class components
167
+ [ key : string ] : any ;
168
+ } ;
169
+ }
170
+
171
+ export interface RootInternal < P = { } >
172
+ extends Exclude < ComponentInternal < P > , 'props' > {
173
+ props : P & { children : ComponentChildren ; _parentDom : PreactNode } ;
174
+ }
175
+
176
+ export interface DomInternal < P = { } > extends BaseInternal < P > {
177
+ type : string ;
178
+ /** The props object for Elements/Components, and the string contents for Text */
179
+ props : ( P & { children : ComponentChildren } ) | string | number ;
180
+ data : PreactNode ;
181
+ }
182
+
183
+ export type Internal < P = { } > =
184
+ | ComponentInternal < P >
185
+ | DomInternal < P >
186
+ | RootInternal < P > ;
187
+
188
+ export type isDomInternal < P = { } > = (
189
+ internal : Internal < P >
190
+ ) => internal is DomInternal < P > ;
191
+ export type isComponentInternal < P = { } > = (
192
+ internal : Internal < P >
193
+ ) => internal is ComponentInternal < P > ;
194
+ export type isRootInternal < P = { } > = (
195
+ internal : Internal < P >
196
+ ) => internal is RootInternal < P > ;
197
+
167
198
export interface Component < P = { } , S = { } > extends preact . Component < P , S > {
168
199
// When component is functional component, this is reset to functional component
169
200
constructor : ComponentType < P > ;
170
201
state : S ; // Override Component["state"] to not be readonly for internal use, specifically Hooks
171
- _internal ?: Internal < P > | null ;
202
+ _internal ?: ComponentInternal < P > | null ;
172
203
_nextState ?: S | null ; // Only class components
173
204
/** Only used in the devtools to later dirty check if state has changed */
174
205
_prevState ?: S | null ;
0 commit comments