Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion designer-demo/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@
// 导入@opentiny/tiny-engine时,内部的依赖包也会逐个导入,可能会执行useComplie,此时需要templateHashMap。所以需要先执行一次defineEntry
import { registry } from './defineEntry.js'
import { init } from '@opentiny/tiny-engine'
import { initHook, HOOK_NAME } from '@opentiny/tiny-engine-entry'
import { configurators } from './configurators.js'
import 'virtual:svg-icons-register'

init({ registry, configurators })
const beforeAppCreate = () => {
initHook(HOOK_NAME.useEnv, import.meta.env)
}

init({ registry, configurators, lifeCycles: { beforeAppCreate } })
16 changes: 14 additions & 2 deletions packages/entry/src/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export const HOOK_NAME = {
useDataSource: 'dataSource',
useBreadcrumb: 'breadcrumb',
useHelp: 'help',
useHttp: 'http',
useEnv: 'env',
Comment thread
chilingling marked this conversation as resolved.
useCustom: 'custom'
}

Expand All @@ -33,6 +35,8 @@ const hooksState = {
[HOOK_NAME.useDataSource]: {},
[HOOK_NAME.useBreadcrumb]: {},
[HOOK_NAME.useHelp]: {},
[HOOK_NAME.useHttp]: {},
[HOOK_NAME.useEnv]: {},
[HOOK_NAME.useCustom]: {} // 自定义
}

Expand All @@ -51,11 +55,19 @@ export const useDataSource = () => hooksState[HOOK_NAME.useDataSource]
export const useBreadcrumb = () => hooksState[HOOK_NAME.useBreadcrumb]
export const useProperty = () => hooksState[HOOK_NAME.useProperty]
export const useHelp = () => hooksState[HOOK_NAME.useHelp]
export const useHttp = () => hooksState[HOOK_NAME.useHttp]
export const useEnv = () => hooksState[HOOK_NAME.useEnv]
export const useCustom = () => hooksState[HOOK_NAME.useCustom]

export function initHook(hookName, hookContent) {
export function initHook(hookName, hookContent, { useDefaultExport } = {}) {
if (!Object.keys(hooksState).includes(hookName)) {
throw new Error('Invalid hook name provided: ' + hookName)
}
Object.assign(hooksState[hookName], hookContent)
if (useDefaultExport) {
hooksState[hookName] = hookContent
} else {
Object.assign(hooksState[hookName], hookContent)
}

return hooksState[hookName]
}
3 changes: 3 additions & 0 deletions packages/http/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import Login from './Login.vue'
import { getConfig } from './config'
import mockData from './mock'
import { constants } from '@opentiny/tiny-engine-utils'
import { initHook, HOOK_NAME } from '@opentiny/tiny-engine-entry'
Comment thread
chilingling marked this conversation as resolved.

const { BROADCAST_CHANNEL } = constants

Expand Down Expand Up @@ -153,3 +154,5 @@ export const initHttp = ({ env }) => {
}

export const useHttp = () => createHttp({ enableMock: isMock() })

initHook(HOOK_NAME.useHttp, useHttp, { useDefaultExport: true })