/** * {wkitd} * @author yutent * @date 2023/08/10 10:02:15 */ import './init.js' import { html, css, Component } from 'wkit' import { noop } from './utils.js' import { __ROUTER__, __STORE__, __ROUTER_VIEW__ } from './constants.js' export * from './router/index.js' export { createStore } from './store.js' class App extends Component {} export function createApp({ data = {}, styles = [], methods = {}, mounted = noop, render } = {}) { // return new (function () { App.props = data App.styles = styles Object.assign(App.prototype, methods, { mounted }) this.use = function (plugin = noop, ...args) { plugin.apply(App.prototype, args) return this } this.mount = function () { let $router = window.wkitd.get(__ROUTER__) if (render) { App.prototype.render = render } else { if ($router) { App.prototype.render = function () { return html`` } } else { App.styles = css` :host { font-family: monospace; color: #647889; } .code { margin: 16px 0; background: #f7f8fb; } ` App.prototype.render = function () { return html`

It works!!!

If you don't use router, you may define the render property.
  createApp({
    render() {
      return html\`<wc-home></wc-home>\`
    }
  })
  .mount()
` } } } if ($router) { App.prototype.mounted = function (...args) { let $view = window.wkitd.get(__ROUTER_VIEW__) if ($view) { $view.sync($router.views) $router.init() // mounted 时正式初始化路由 mounted.call(this, ...args) } else { throw new Error( ` not found, "Router" works Unexpected.` ) } } } App.reg('app') } })() } export function getStore() { return window.wkitd.get(__STORE__) } export function getRouter() { return window.wkitd.get(__ROUTER__) } export function getCurrentPage() { return window.wkitd.get(__ROUTER__)?.route }