Skip to content

Commit

Permalink
feat: add app lifecycle
Browse files Browse the repository at this point in the history
  • Loading branch information
hexqi committed May 28, 2024
1 parent 87cb3eb commit da8b539
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 74 deletions.
15 changes: 0 additions & 15 deletions designer-demo/src/App.vue

This file was deleted.

12 changes: 12 additions & 0 deletions designer-demo/src/canvas.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
/**
* Copyright (c) 2023 - present TinyEngine Authors.
* Copyright (c) 2023 - present Huawei Cloud Computing Technologies Co., Ltd.
*
* Use of this source code is governed by an MIT-style license.
*
* THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
* BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
* A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
*
*/

import { createRender } from '@opentiny/tiny-engine-canvas'

createRender(window.parent.TinyGlobalConfig)
15 changes: 0 additions & 15 deletions designer-demo/src/defineEntry.js

This file was deleted.

13 changes: 7 additions & 6 deletions designer-demo/src/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Copyright (c) 2024 - present TinyEngine Authors.
* Copyright (c) 2024 - present Huawei Cloud Computing Technologies Co., Ltd.
* Copyright (c) 2023 - present TinyEngine Authors.
* Copyright (c) 2023 - present Huawei Cloud Computing Technologies Co., Ltd.
*
* Use of this source code is governed by an MIT-style license.
*
Expand All @@ -10,8 +10,9 @@
*
*/

import './defineEntry.js'
import { createApp } from 'vue'
import App from './App.vue'
import registry from '../registry.js'
import { defineEntry } from '@opentiny/tiny-engine-entry'
import { init } from '@opentiny/tiny-engine'

createApp(App).mount('#app')
defineEntry(registry)
init()
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"preinstall": "npx only-allow pnpm",
"dev": "pnpm run setup && concurrently 'pnpm:serve:backend' 'pnpm:serve:frontend'",
"dev:mock": "pnpm --filter @opentiny/tiny-engine dev",
"dev:demo": "concurrently 'pnpm:serve:backend' 'pnpm:dev:demo:frontend'",
"dev:demo": "pnpm run setup && concurrently 'pnpm:serve:backend' 'pnpm:dev:demo:frontend'",
"serve:frontend": "pnpm --filter @opentiny/tiny-engine serve",
"dev:demo:frontend": "pnpm --filter designer-demo dev",
"serve:backend": "pnpm --filter @opentiny/tiny-engine-mock dev",
Expand Down
69 changes: 33 additions & 36 deletions packages/design-core/src/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,45 +52,42 @@ const mergeRegistry = (registry) => {
return registry
}

const beforeAppCreate = ({ selector, registry }) => {
// 合并用户自定义注册表
const newRegistry = mergeRegistry(registry)

// 在common层注入合并后的注册表
defineEntry(newRegistry)

initHttp({ env: import.meta.env })

// eslint-disable-next-line no-new
new TinyThemeTool(tinySmbTheme, 'smbtheme') // 初始化主题

if (import.meta.env.VITE_ERROR_MONITOR === 'true' && import.meta.env.VITE_ERROR_MONITOR_URL) {
initMonitor(import.meta.env.VITE_ERROR_MONITOR_URL)
}

window.TinyGlobalConfig = globalConfig
setGlobalConfig(globalConfig)
}

const appCreated = (app) => {
initSvgs(app)
window.lowcodeI18n = i18n
app.use(i18n).use(injectGlobalComponents)
}

const beforeAppMounted = (app) => {

const defaultLifeCycles = {
beforeAppCreate: ({ selector, registry }) => {
// 合并用户自定义注册表
const newRegistry = mergeRegistry(registry)

// 在common层注入合并后的注册表
defineEntry(newRegistry)

initHttp({ env: import.meta.env })

// eslint-disable-next-line no-new
new TinyThemeTool(tinySmbTheme, 'smbtheme') // 初始化主题

if (import.meta.env.VITE_ERROR_MONITOR === 'true' && import.meta.env.VITE_ERROR_MONITOR_URL) {
initMonitor(import.meta.env.VITE_ERROR_MONITOR_URL)
}

window.TinyGlobalConfig = globalConfig
setGlobalConfig(globalConfig)
},
appCreated: (app) => {
initSvgs(app)
window.lowcodeI18n = i18n
app.use(i18n).use(injectGlobalComponents)
}
}

const appMounted = (app) => {
export const init = (selector = '#app', registry = defaultRegistry, lifeCycles = {}) => {
const { beforeAppCreate, appCreated, appMounted } = lifeCycles

}

export const init = (selector = '#app', registry = defaultRegistry) => {
beforeAppCreate({ selector, registry })
defaultLifeCycles.beforeAppCreate({ selector, registry })
beforeAppCreate?.({ selector, registry })
const app = createApp(App)
appCreated(app)
beforeAppMounted(app)
defaultLifeCycles.appCreated(app)
appCreated?.(app)

app.mount(selector)
appMounted(app)
appMounted?.(app)
}
2 changes: 1 addition & 1 deletion scripts/setup.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
const { exec } = require('child_process')

exec('pnpm -F @opentiny/tiny-engine-controller -F @opentiny/tiny-engine-dsl-vue build')
exec('pnpm -F @opentiny/vite-plugin-generate-comments -F @opentiny/tiny-engine-controller -F @opentiny/tiny-engine-dsl-vue build')

0 comments on commit da8b539

Please sign in to comment.