( render: RootRenderFunction<HostElement>, hydrate?: RootHydrateFunction, )
| 251 | let uid = 0 |
| 252 | |
| 253 | export function createAppAPI<HostElement>( |
| 254 | render: RootRenderFunction<HostElement>, |
| 255 | hydrate?: RootHydrateFunction, |
| 256 | ): CreateAppFunction<HostElement> { |
| 257 | return function createApp(rootComponent, rootProps = null) { |
| 258 | if (!isFunction(rootComponent)) { |
| 259 | rootComponent = extend({}, rootComponent) |
| 260 | } |
| 261 | |
| 262 | if (rootProps != null && !isObject(rootProps)) { |
| 263 | __DEV__ && warn(`root props passed to app.mount() must be an object.`) |
| 264 | rootProps = null |
| 265 | } |
| 266 | |
| 267 | const context = createAppContext() |
| 268 | const installedPlugins = new WeakSet() |
| 269 | const pluginCleanupFns: Array<() => any> = [] |
| 270 | |
| 271 | let isMounted = false |
| 272 | |
| 273 | const app: App = (context.app = { |
| 274 | _uid: uid++, |
| 275 | _component: rootComponent as ConcreteComponent, |
| 276 | _props: rootProps, |
| 277 | _container: null, |
| 278 | _context: context, |
| 279 | _instance: null, |
| 280 | |
| 281 | version, |
| 282 | |
| 283 | get config() { |
| 284 | return context.config |
| 285 | }, |
| 286 | |
| 287 | set config(v) { |
| 288 | if (__DEV__) { |
| 289 | warn( |
| 290 | `app.config cannot be replaced. Modify individual options instead.`, |
| 291 | ) |
| 292 | } |
| 293 | }, |
| 294 | |
| 295 | use(plugin: Plugin, ...options: any[]) { |
| 296 | if (installedPlugins.has(plugin)) { |
| 297 | __DEV__ && warn(`Plugin has already been applied to target app.`) |
| 298 | } else if (plugin && isFunction(plugin.install)) { |
| 299 | installedPlugins.add(plugin) |
| 300 | plugin.install(app, ...options) |
| 301 | } else if (isFunction(plugin)) { |
| 302 | installedPlugins.add(plugin) |
| 303 | plugin(app, ...options) |
| 304 | } else if (__DEV__) { |
| 305 | warn( |
| 306 | `A plugin must either be a function or an object with an "install" ` + |
| 307 | `function.`, |
| 308 | ) |
| 309 | } |
| 310 | return app |
no test coverage detected