Files
cut-abstractions/samples/demoDatahandle/demoDataHandle1.ts

75 lines
2.4 KiB
TypeScript
Raw Normal View History

import { ProcessorModule, StepControllerProcessor } from "../../src/device";
import { RectOptimizeMachineModule } from "../moduleManager/module1";
/**
* demo
*
*
*/
export class demoHandleGroupCutting {
processorName = "cutting"
processor: StepControllerProcessor<any, any>
constructor() {
const callbackStyleModule: ProcessorModule<any, any> = {
moduleName: "callbackStyle",
process(input, next, context) {
console.log("做优化");
const _input = input
const _next = next
const _context = context
// 可以在这里调用异步操作
Reflect.set(context, 'CallBack', callBack1)
// 决定是否调用 next
function callBack1(v) {
console.log('接收到其它模块回传的数据', v);
}
// 调用 next 继续流程
return next(input);
}
};
const demoModule: ProcessorModule<string, string> = {
moduleName: "demoModule",
process(input, next, context) {
// 写入上下文
context.processedAt = new Date().toLocaleString();
context.originalLength = input.length;
// 设置下一步需要的上下文
context.previousStep = "demoModule";
if (context.CallBack) {
context.CallBack("demoModule end and callback")
}
return next(input);
}
};
this.processor = new StepControllerProcessor<any, any>();
this.processor.use([
{
moduleName: "traditional",
handle(input, next) {
// 第一个流程
console.log(`第一个模块功能:有${input?.blockList.length}片小板,可以做些计算`)
return next ? next(input) : input;
}
},
callbackStyleModule,
demoModule,
RectOptimizeMachineModule,
{
moduleName: "final",
process(input, next) {
// 不调用 next终止流程
console.log('结束了')
return next(input);
}
}
])
}
}