How to use tsyringe - 10 common examples

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 Arianee / arianeeJS / src / core / wallet / services / arianeeEventEmitterService / ArianeeEventEmitter.ts View on Github external
newListener='newListener'
}
export class CustomEventEmitter extends EventEmitter {
  on (...args) {
    if (args[0] !== ArianeListenerEvent.newListener) {
      super.emit(ArianeListenerEvent.newListener, args[0]);
    }

    // @ts-ignore
    return super.on(...args);
  }

  addListener=this.on;
}

@singleton()
export class ArianeeEventEmitter {
  public EE = new CustomEventEmitter();
}
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 ckaznocha / ide-go / lib / ide-go.ts View on Github external
import DatatipAdapter from 'atom-languageclient/build/lib/adapters/datatip-adapter'
// tslint:disable-next-line: no-import-side-effect
import 'reflect-metadata'
import { container } from 'tsyringe'
import { GoDatatipAdapter } from './datatip-adapter'
import { GoLanguageClient } from './language-client'

const client: GoLanguageClient = container
    .register(DatatipAdapter, {
        useClass: GoDatatipAdapter,
    })
    .resolve(GoLanguageClient)

module.exports = client
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 / index.ts View on Github external
import 'reflect-metadata';

import Application from './Application';
import consoleFrameStyle from './site-style';
import { ConsoleFramePresenterImpl } from './presenters/ConsoleFramePresenter';
import { container } from 'tsyringe';
import './di';

if (window.self === window.top) {
  new ConsoleFramePresenterImpl().initialize();
}

try {
  const app = container.resolve(Application);
  app.run();
} catch (e) { console.error(e); }

const style = window.document.createElement('style');
style.textContent = consoleFrameStyle;
window.document.head.appendChild(style);
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();
  }
}

tsyringe

Lightweight dependency injection container for JavaScript/TypeScript

MIT
Latest version published 2 years ago

Package Health Score

64 / 100
Full package analysis