diff --git a/bin/cli/worker/cli.worker.js b/bin/cli/worker/cli.worker.js index cfd331c8b..02a7c803a 100644 --- a/bin/cli/worker/cli.worker.js +++ b/bin/cli/worker/cli.worker.js @@ -45,6 +45,7 @@ module.exports = { 'action.worker_ability_test.ts': path.resolve(__dirname, './template/main_thread/action/action.worker_ability_test.t'), }, [`${name}_main_thread.ts`]: path.resolve(__dirname, './template/main_thread/main_thread.t'), + [`${name}_main_thread.helper.ts`]: path.resolve(__dirname, './template/main_thread/main_thread.helper.t'), }, utils: { 'action_type.ts': path.resolve(__dirname, './template/utils/action_type.t'), diff --git a/bin/cli/worker/template/main_thread/main_thread.helper.t b/bin/cli/worker/template/main_thread/main_thread.helper.t new file mode 100644 index 000000000..defe01502 --- /dev/null +++ b/bin/cli/worker/template/main_thread/main_thread.helper.t @@ -0,0 +1,26 @@ +import { ${WorkerName}MainThreadWorker } from './new_main_thread'; +// 不需要一起打包的话则不需要引入这行 +import { workerUrl } from 'fui-worker!../worker_thread/new_worker_thread'; + +// MainThread的创建在helper层处理 +export class ${WorkerName}MainThreadWorkerHelper { + public createMainTreadWorker() { + return BI.Workers.createWorker(${WorkerName}MainThreadWorker, { + workerUrl: this.urlFormatter(workerUrl), + workerName: BI.UUID(), + }); + } + + private urlFormatter(v: string) { + return v; + } +} + +export const mainThreadWorkerHelper = new ${WorkerName}MainThreadWorkerHelper(); + +// 调用示例 +mainThreadWorkerHelper.createMainTreadWorker() + .testCommunication() + .then(res => { + console.log(res) + }) \ No newline at end of file diff --git a/bin/cli/worker/template/main_thread/main_thread.t b/bin/cli/worker/template/main_thread/main_thread.t index 75f8fb674..00fb09177 100644 --- a/bin/cli/worker/template/main_thread/main_thread.t +++ b/bin/cli/worker/template/main_thread/main_thread.t @@ -1,8 +1,6 @@ import { WorkerAbilityTestMainThreadAction } from './action/action.worker_ability_test'; -// 不需要一起打包的话则不需要引入这行 -import { workerUrl } from 'fui-worker!../worker_thread/${workerName}_worker_thread'; -class ${WorkerName}MainTreadWorker extends BI.Workers.MainThreadWorker { +export class ${WorkerName}MainThreadWorker extends BI.Workers.MainThreadWorker { private communicationTest: WorkerAbilityTestMainThreadAction; public initActions(): void { @@ -13,13 +11,3 @@ class ${WorkerName}MainTreadWorker extends BI.Workers.MainThreadWorker { return this.communicationTest.communicationTest(); } } - -const ${workerName}MainTreadWorker = BI.Workers.createWorker(${WorkerName}MainTreadWorker, { - workerUrl, - workerName: BI.UUID(), -}); - -${workerName}MainTreadWorker.testCommunication() - .then(v => { - console.log(v); - });