How to use the tsyringe.injectable function in tsyringe

To help you get started, we’ve selected a few tsyringe examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ueokande / vim-vixen / src / background / usecases / RepeatUseCase.ts View on Github external
import { injectable } from 'tsyringe';
import * as operations from '../../shared/operations';
import RepeatRepository from '../repositories/RepeatRepository';

type Operation = operations.Operation;

@injectable()
export default class RepeatUseCase {
  constructor(
    private repeatRepository: RepeatRepository,
  ) {
  }

  storeLastOperation(op: Operation): void {
    this.repeatRepository.setLastOperation(op);
  }

  getLastOperation(): operations.Operation | undefined {
    return this.repeatRepository.getLastOperation();
  }

  // eslint-disable-next-line complexity
  isRepeatable(op: Operation): boolean {
github ueokande / vim-vixen / src / background / repositories / BrowserSettingRepository.ts View on Github external
type BrowserSettings = {
    value: string;
    levelOfControl: LevelOfControlType;
  };

  type LevelOfControlType =
    'not_controllable' |
    'controlled_by_other_extensions' |
    'controllable_by_this_extension' |
    'controlled_by_this_extension';

  function get(param: object): Promise;
}

@injectable()
export default class BrowserSettingRepository {
  async getHomepageUrls(): Promise {
    const { value } = await browser.browserSettings.homepageOverride.get({});
    return value.split('|').map(urls.normalizeUrl);
  }
}
github ueokande / vim-vixen / src / content / usecases / KeymapUseCase.ts View on Github external
import Keymaps from '../../shared/settings/Keymaps';
import Key from '../../shared/settings/Key';
import KeySequence from '../domains/KeySequence';
import AddressRepository from '../repositories/AddressRepository';

const reservedKeymaps = Keymaps.fromJSON({
  '': { type: operations.CANCEL },
  '': { type: operations.CANCEL },
});

const enableAddonOps = [
  operations.ADDON_ENABLE,
  operations.ADDON_TOGGLE_ENABLED,
];

@injectable()
export default class KeymapUseCase {
  constructor(
    @inject('KeymapRepository')
    private repository: KeymapRepository,

    @inject('SettingRepository')
    private settingRepository: SettingRepository,

    @inject('AddonEnabledRepository')
    private addonEnabledRepository: AddonEnabledRepository,

    @inject('AddressRepository')
    private addressRepository: AddressRepository,
  ) {
  }
github Arianee / arianeeJS / src / core / wallet / services / walletService / walletService.ts View on Github external
import { injectable, singleton } from 'tsyringe';

@injectable()
export class WalletService {
  public account;

  public get publicKey (): string {
    return this.account.address;
  }

  public get privateKey (): string {
    return this.account.privateKey;
  }

  public bdhVaultURL:string;

  public isBdhVault ():boolean {
    return this.bdhVaultURL !== undefined;
  }
github ueokande / vim-vixen / src / background / controllers / MarkController.ts View on Github external
import { injectable } from 'tsyringe';
import MarkUseCase from '../usecases/MarkUseCase';

@injectable()
export default class MarkController {
  constructor(
    private markUseCase: MarkUseCase,
  ) {
  }

  setGlobal(key: string, x: number, y: number): Promise {
    return this.markUseCase.setGlobal(key, x, y);
  }

  jumpGlobal(key: string): Promise {
    return this.markUseCase.jumpGlobal(key);
  }
}
github ueokande / vim-vixen / src / background / controllers / OperationController.ts View on Github external
import { injectable } from 'tsyringe';
import * as operations from '../../shared/operations';
import FindUseCase from '../usecases/FindUseCase';
import ConsoleUseCase from '../usecases/ConsoleUseCase';
import TabUseCase from '../usecases/TabUseCase';
import TabSelectUseCase from '../usecases/TabSelectUseCase';
import ZoomUseCase from '../usecases/ZoomUseCase';
import NavigateUseCase from '../usecases/NavigateUseCase';
import RepeatUseCase from '../usecases/RepeatUseCase';

@injectable()
export default class OperationController {
  constructor(
    private findUseCase: FindUseCase,
    private consoleUseCase: ConsoleUseCase,
    private tabUseCase: TabUseCase,
    private tabSelectUseCase: TabSelectUseCase,
    private zoomUseCase: ZoomUseCase,
    private navigateUseCase: NavigateUseCase,
    private repeatUseCase: RepeatUseCase,
  ) {
  }

  async exec(count: number, op: operations.Operation): Promise {
    await this.doOperation(count, op);
    if (this.repeatUseCase.isRepeatable(op)) {
      this.repeatUseCase.storeLastOperation(op);
github ueokande / vim-vixen / src / background / repositories / FindRepository.ts View on Github external
import { injectable } from 'tsyringe';
import MemoryStorage from '../infrastructures/MemoryStorage';

const FIND_KEYWORD_KEY = 'find-keyword';

@injectable()
export default class FindRepository {
  private cache: MemoryStorage;

  constructor() {
    this.cache = new MemoryStorage();
  }

  getKeyword(): Promise {
    return Promise.resolve(this.cache.get(FIND_KEYWORD_KEY));
  }

  setKeyword(keyword: string): Promise {
    this.cache.set(FIND_KEYWORD_KEY, keyword);
    return Promise.resolve();
  }
}
github ueokande / vim-vixen / src / content / controllers / FollowKeyController.ts View on Github external
import { injectable } from 'tsyringe';
import FollowSlaveUseCase from '../usecases/FollowSlaveUseCase';
import Key from '../../shared/settings/Key';

@injectable()
export default class FollowKeyController {
  constructor(
    private followSlaveUseCase: FollowSlaveUseCase,
  ) {
  }

  press(key: Key): boolean {
    if (!this.followSlaveUseCase.isFollowMode()) {
      return false;
    }

    this.followSlaveUseCase.sendKey(key);
    return true;
  }
}
github ueokande / vim-vixen / src / background / usecases / MarkUseCase.ts View on Github external
import { injectable } from 'tsyringe';
import TabPresenter from '../presenters/TabPresenter';
import MarkRepository from '../repositories/MarkRepository';
import ConsoleClient from '../infrastructures/ConsoleClient';
import ContentMessageClient from '../infrastructures/ContentMessageClient';

@injectable()
export default class MarkUseCase {
  constructor(
    private tabPresenter: TabPresenter,
    private markRepository: MarkRepository,
    private consoleClient: ConsoleClient,
    private contentMessageClient: ContentMessageClient,
  ) {
  }

  async setGlobal(key: string, x: number, y: number): Promise {
    const tab = await this.tabPresenter.getCurrent();
    const mark = { tabId: tab.id as number, url: tab.url as string, x, y };
    return this.markRepository.setMark(key, mark);
  }

  async jumpGlobal(key: string): Promise {
github ueokande / vim-vixen / src / background / repositories / MarkRepository.ts View on Github external
import { injectable } from 'tsyringe';
import MemoryStorage from '../infrastructures/MemoryStorage';
import GlobalMark from '../domains/GlobalMark';

const MARK_KEY = 'mark';

@injectable()
export default class MarkRepository {
  private cache: MemoryStorage;

  constructor() {
    this.cache = new MemoryStorage();
  }

  getMark(key: string): Promise {
    const marks = this.getOrEmptyMarks();
    const data = marks[key];
    if (!data) {
      return Promise.resolve(undefined);
    }
    const mark = { tabId: data.tabId, url: data.url, x: data.x, y: data.y };
    return Promise.resolve(mark);
  }

tsyringe

Lightweight dependency injection container for JavaScript/TypeScript

MIT
Latest version published 1 year ago

Package Health Score

68 / 100
Full package analysis