diff options
Diffstat (limited to 'src/content/operators/impls/AddonOperatorFactoryChain.ts')
-rw-r--r-- | src/content/operators/impls/AddonOperatorFactoryChain.ts | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/content/operators/impls/AddonOperatorFactoryChain.ts b/src/content/operators/impls/AddonOperatorFactoryChain.ts new file mode 100644 index 0000000..54880c4 --- /dev/null +++ b/src/content/operators/impls/AddonOperatorFactoryChain.ts @@ -0,0 +1,40 @@ +import { inject, injectable } from "tsyringe"; +import OperatorFactoryChain from "../OperatorFactoryChain"; +import AddonIndicatorClient from "../../client/AddonIndicatorClient"; +import AddonEnabledRepository from "../../repositories/AddonEnabledRepository"; +import * as operations from "../../../shared/operations"; +import Operator from "../Operator"; +import EnableAddonOperator from "./EnableAddonOperator"; +import DisableAddonOperator from "./DisableAddonOperator"; +import ToggleAddonOperator from "./ToggleAddonOperator"; + +@injectable() +export default class AddonOperatorFactoryChain implements OperatorFactoryChain { + constructor( + @inject("AddonIndicatorClient") + private readonly addonIndicatorClient: AddonIndicatorClient, + @inject("AddonEnabledRepository") + private readonly addonEnabledRepository: AddonEnabledRepository + ) {} + + create(op: operations.Operation, _repeat: number): Operator | null { + switch (op.type) { + case operations.ADDON_ENABLE: + return new EnableAddonOperator( + this.addonIndicatorClient, + this.addonEnabledRepository + ); + case operations.ADDON_DISABLE: + return new DisableAddonOperator( + this.addonIndicatorClient, + this.addonEnabledRepository + ); + case operations.ADDON_TOGGLE_ENABLED: + return new ToggleAddonOperator( + this.addonIndicatorClient, + this.addonEnabledRepository + ); + } + return null; + } +} |