cross-magic
Version:
跨平台公共模块
43 lines (36 loc) • 948 B
text/typescript
import { RunTime, RunTimeData } from './runTime'
import EnumRunTimePlatForm from '@/common/constants/runTimePlatform'
import WebRunTime from './webRunTime'
import WxMpRuntime from './wxMpRunTime'
let runTime!: RunTime
let runTimeData!: RunTimeData
export function createRuntime(data: RunTimeData) {
if (!data) {
throw new Error('createRuntime param data is null')
}
if (runTime) {
return runTime
}
runTimeData = data
switch (runTimeData.runTimePlatform) {
case EnumRunTimePlatForm.web:
runTime = new WebRunTime(runTimeData)
break
case EnumRunTimePlatForm.wxMp:
runTime = new WxMpRuntime(runTimeData)
break
case EnumRunTimePlatForm.zfbMp:
break
default:
throw new Error('createRuntime err: unknown platform')
break
}
return runTime
}
export function getRunTimeData() {
return runTimeData
}
function getRunTime() {
return runTime
}
export default getRunTime