@@ -62,10 +62,24 @@ import {
62
62
import { ErrorCodes , callWithErrorHandling } from './errorHandling'
63
63
import { KeepAliveSink , isKeepAlive } from './components/KeepAlive'
64
64
import { registerHMR , unregisterHMR } from './hmr'
65
- import { createHydrationFunctions } from './hydration'
65
+ import { createHydrationFunctions , RootHydrateFunction } from './hydration'
66
66
67
67
const __HMR__ = __BUNDLER__ && __DEV__
68
68
69
+ export interface Renderer < HostNode = any , HostElement = any > {
70
+ render : RootRenderFunction < HostNode , HostElement >
71
+ createApp : CreateAppFunction < HostElement >
72
+ }
73
+
74
+ export interface HydrationRenderer extends Renderer < Node , Element > {
75
+ hydrate : RootHydrateFunction
76
+ }
77
+
78
+ export type RootRenderFunction < HostNode , HostElement > = (
79
+ vnode : VNode < HostNode , HostElement > | null ,
80
+ container : HostElement
81
+ ) => void
82
+
69
83
export interface RendererOptions < HostNode = any , HostElement = any > {
70
84
patchProp (
71
85
el : HostElement ,
@@ -102,41 +116,6 @@ export interface RendererOptions<HostNode = any, HostElement = any> {
102
116
) : HostElement
103
117
}
104
118
105
- export type RootRenderFunction < HostNode , HostElement > = (
106
- vnode : VNode < HostNode , HostElement > | null ,
107
- dom : HostElement
108
- ) => void
109
-
110
- // An object exposing the internals of a renderer, passed to tree-shakeable
111
- // features so that they can be decoupled from this file.
112
- export interface RendererInternals < HostNode = any , HostElement = any > {
113
- patch : (
114
- n1 : VNode < HostNode , HostElement > | null , // null means this is a mount
115
- n2 : VNode < HostNode , HostElement > ,
116
- container : HostElement ,
117
- anchor ?: HostNode | null ,
118
- parentComponent ?: ComponentInternalInstance | null ,
119
- parentSuspense ?: SuspenseBoundary < HostNode , HostElement > | null ,
120
- isSVG ?: boolean ,
121
- optimized ?: boolean
122
- ) => void
123
- unmount : (
124
- vnode : VNode < HostNode , HostElement > ,
125
- parentComponent : ComponentInternalInstance | null ,
126
- parentSuspense : SuspenseBoundary < HostNode , HostElement > | null ,
127
- doRemove ?: boolean
128
- ) => void
129
- move : (
130
- vnode : VNode < HostNode , HostElement > ,
131
- container : HostElement ,
132
- anchor : HostNode | null ,
133
- type : MoveType ,
134
- parentSuspense ?: SuspenseBoundary < HostNode , HostElement > | null
135
- ) => void
136
- next : ( vnode : VNode < HostNode , HostElement > ) => HostNode | null
137
- options : RendererOptions < HostNode , HostElement >
138
- }
139
-
140
119
export const enum MoveType {
141
120
ENTER ,
142
121
LEAVE ,
@@ -186,25 +165,36 @@ export function createRenderer<
186
165
HostNode extends object = any ,
187
166
HostElement extends HostNode = any
188
167
> ( options : RendererOptions < HostNode , HostElement > ) {
189
- const res = baseCreateRenderer ( options )
190
- return res as typeof res & {
191
- hydrate : undefined
192
- }
168
+ return baseCreateRenderer < HostNode , HostElement > ( options )
193
169
}
194
170
195
171
// Separate API for creating hydration-enabled renderer.
196
172
// Hydration logic is only used when calling this function, making it
197
173
// tree-shakable.
198
- export function createHydrationRenderer <
174
+ export function createHydrationRenderer (
175
+ options : RendererOptions < Node , Element >
176
+ ) {
177
+ return baseCreateRenderer < Node , Element > ( options , createHydrationFunctions )
178
+ }
179
+
180
+ // overload 1: no hydration
181
+ function baseCreateRenderer <
199
182
HostNode extends object = any ,
200
183
HostElement extends HostNode = any
201
- > ( options : RendererOptions < HostNode , HostElement > ) {
202
- const res = baseCreateRenderer ( options , createHydrationFunctions )
203
- return res as typeof res & {
204
- hydrate : ReturnType < typeof createHydrationFunctions > [ 0 ]
205
- }
206
- }
184
+ > (
185
+ options : RendererOptions < HostNode , HostElement >
186
+ ) : Renderer < HostNode , HostElement >
187
+
188
+ // overload 2: with hydration
189
+ function baseCreateRenderer <
190
+ HostNode extends object = any ,
191
+ HostElement extends HostNode = any
192
+ > (
193
+ options : RendererOptions < HostNode , HostElement > ,
194
+ createHydrationFns : typeof createHydrationFunctions
195
+ ) : HydrationRenderer
207
196
197
+ // implementation
208
198
function baseCreateRenderer <
209
199
HostNode extends object = any ,
210
200
HostElement extends HostNode = any
@@ -1862,6 +1852,36 @@ function baseCreateRenderer<
1862
1852
}
1863
1853
}
1864
1854
1855
+ // An object exposing the internals of a renderer, passed to tree-shakeable
1856
+ // features so that they can be decoupled from this file.
1857
+ export interface RendererInternals < HostNode = any , HostElement = any > {
1858
+ patch : (
1859
+ n1 : VNode < HostNode , HostElement > | null , // null means this is a mount
1860
+ n2 : VNode < HostNode , HostElement > ,
1861
+ container : HostElement ,
1862
+ anchor ?: HostNode | null ,
1863
+ parentComponent ?: ComponentInternalInstance | null ,
1864
+ parentSuspense ?: SuspenseBoundary < HostNode , HostElement > | null ,
1865
+ isSVG ?: boolean ,
1866
+ optimized ?: boolean
1867
+ ) => void
1868
+ unmount : (
1869
+ vnode : VNode < HostNode , HostElement > ,
1870
+ parentComponent : ComponentInternalInstance | null ,
1871
+ parentSuspense : SuspenseBoundary < HostNode , HostElement > | null ,
1872
+ doRemove ?: boolean
1873
+ ) => void
1874
+ move : (
1875
+ vnode : VNode < HostNode , HostElement > ,
1876
+ container : HostElement ,
1877
+ anchor : HostNode | null ,
1878
+ type : MoveType ,
1879
+ parentSuspense ?: SuspenseBoundary < HostNode , HostElement > | null
1880
+ ) => void
1881
+ next : ( vnode : VNode < HostNode , HostElement > ) => HostNode | null
1882
+ options : RendererOptions < HostNode , HostElement >
1883
+ }
1884
+
1865
1885
// https://en.wikipedia.org/wiki/Longest_increasing_subsequence
1866
1886
function getSequence ( arr : number [ ] ) : number [ ] {
1867
1887
const p = arr . slice ( )
0 commit comments