Browse Source

Merge branch 'master' of ssh://code.fineres.com:7999/~dailer/fineui

es6
zsmj 2 years ago
parent
commit
d43d0d653f
  1. 1
      bin/cli/worker/cli.worker.js
  2. 45
      bin/cli/worker/template/main_thread.helper.t
  3. 14
      bin/cli/worker/template/main_thread/main_thread.t
  4. 2
      package.json

1
bin/cli/worker/cli.worker.js

@ -56,6 +56,7 @@ module.exports = {
}, },
[`${name}_worker_thread.ts`]: path.resolve(__dirname, './template/worker_thread/worker_thread.t'), [`${name}_worker_thread.ts`]: path.resolve(__dirname, './template/worker_thread/worker_thread.t'),
}, },
[`${name}_main_thread.helper.ts`]: path.resolve(__dirname, './template/main_thread.helper.t'),
}, },
}; };

45
bin/cli/worker/template/main_thread.helper.t

@ -0,0 +1,45 @@
import { ${WorkerName}MainThreadWorker } from './main_thread/${workerName}_main_thread';
// 不需要一起打包的话则不需要引入这行
import { workerUrl } from 'fui-worker!./worker_thread/${workerName}_worker_thread';
export class ${WorkerName}WorkerHelper {
private worker: ${WorkerName}MainThreadWorker;
/**
* 拿到helper中的worker
*/
public getWorker() {
if (this.worker) {
return this.worker;
}
this.worker = BI.Workers.createWorker(${WorkerName}MainThreadWorker, {
workerUrl: this.urlFormatter(workerUrl),
workerName: BI.UUID(),
});
return this.worker;
}
/**
* 格式化worker url比如补充一些环境信息到参数里
* @param url worker url
*/
private urlFormatter(url: string) {
return url;
}
/**
* 终止worker
*/
public terminate() {
this.worker?.terminate();
}
}
// 使用示例
// const workerHelper = new ${WorkerName}WorkerHelper();
// workerHelper.getWorker()
// .testCommunication()
// .then(res => console.log(res));

14
bin/cli/worker/template/main_thread/main_thread.t

@ -1,8 +1,6 @@
import { WorkerAbilityTestMainThreadAction } from './action/action.worker_ability_test'; 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; private communicationTest: WorkerAbilityTestMainThreadAction;
public initActions(): void { public initActions(): void {
@ -13,13 +11,3 @@ class ${WorkerName}MainTreadWorker extends BI.Workers.MainThreadWorker {
return this.communicationTest.communicationTest(); return this.communicationTest.communicationTest();
} }
} }
const ${workerName}MainTreadWorker = BI.Workers.createWorker(${WorkerName}MainTreadWorker, {
workerUrl,
workerName: BI.UUID(),
});
${workerName}MainTreadWorker.testCommunication()
.then(v => {
console.log(v);
});

2
package.json

@ -1,6 +1,6 @@
{ {
"name": "fineui", "name": "fineui",
"version": "2.0.20220726155349", "version": "2.0.20220727111551",
"description": "fineui", "description": "fineui",
"main": "dist/fineui_without_conflict.min.js", "main": "dist/fineui_without_conflict.min.js",
"types": "dist/lib/index.d.ts", "types": "dist/lib/index.d.ts",

Loading…
Cancel
Save