diff options
Diffstat (limited to 'src/background/operators/impls/OperatorFactoryImpl.ts')
-rw-r--r-- | src/background/operators/impls/OperatorFactoryImpl.ts | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/background/operators/impls/OperatorFactoryImpl.ts b/src/background/operators/impls/OperatorFactoryImpl.ts new file mode 100644 index 0000000..34e7bb5 --- /dev/null +++ b/src/background/operators/impls/OperatorFactoryImpl.ts @@ -0,0 +1,45 @@ +import { inject, delay, injectable } from "tsyringe"; +import Operator from "../Operator"; +import OperatorFactory from "../OperatorFactory"; +import OperatorFactoryChain from "../OperatorFactoryChain"; +import CommandOperatorFactoryChain from "./CommandOperatorFactoryChain"; +import InternalOperatorFactoryChain from "./InternalOperatorFactoryChain"; +import NavigateOperatorFactoryChain from "./NavigateOperatorFactoryChain"; +import RepeatOperatorFactoryChain from "./RepeatOperatorFactoryChain"; +import TabOperatorFactoryChain from "./TabOperatorFactoryChain"; +import ZoomOperatorFactoryChain from "./ZoomOperatorFactoryChain"; +import * as operations from "../../../shared/operations"; + +@injectable() +export class OperatorFactoryImpl implements OperatorFactory { + private readonly factoryChains: OperatorFactoryChain[]; + + constructor( + commandOperatorFactoryChain: CommandOperatorFactoryChain, + internalOperatorFactoryChain: InternalOperatorFactoryChain, + navigateOperatorFactoryChain: NavigateOperatorFactoryChain, + tabOperatorFactoryChain: TabOperatorFactoryChain, + zoomOperatorFactoryChain: ZoomOperatorFactoryChain, + @inject(delay(() => RepeatOperatorFactoryChain)) + repeatOperatorFactoryChain: RepeatOperatorFactoryChain + ) { + this.factoryChains = [ + commandOperatorFactoryChain, + internalOperatorFactoryChain, + navigateOperatorFactoryChain, + repeatOperatorFactoryChain, + tabOperatorFactoryChain, + zoomOperatorFactoryChain, + ]; + } + + create(op: operations.Operation): Operator { + for (const chain of this.factoryChains) { + const operator = chain.create(op); + if (operator !== null) { + return operator; + } + } + throw new Error("unknown operation: " + op.type); + } +} |