How to use the constitute.Dependencies function in constitute

To help you get started, we’ve selected a few constitute 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 IdleLands / IdleLands3 / src / plugins / statistics / statistics.js View on Github external
import { Dependencies, Container } from 'constitute';
import * as _ from 'lodash';

import { Logger } from '../../shared/logger';

@Dependencies(Container)
export class Statistics {
  constructor(container) {
    const StatisticsDb = require('./statistics.db').StatisticsDb;
    try {
      container.schedulePostConstructor((statisticsDb) => {
        this.statisticsDb = statisticsDb;
      }, [StatisticsDb]);
    } catch (e) {
      Logger.error('Statistics', e);
    }
  }

  // clear current variables and set new
  init(opts) {
    this._id = undefined;
    this.stats = undefined;
github EvaEngine / EvaEngine.js / src / services / http_client.js View on Github external
bodyLength > maxBodyLength ? TOO_LONG_BODY : res.body || ''
      );
    }).on('redirect', function () {

      logger.verbose('[HTTP_REDIRECT_%s] [%s %s] [%s] [RES_HEADERS: %s] [RES_BODY: %s]', this._debugId,
        this.method.toUpperCase(), this.uri.href, this.response.statusCode, JSON.stringify(ignoreDebug(this.response.headers)), '');
    });
    this._debugId = ++debugId;
    return proto._initBeforeDebug.apply(this, arguments);
  };

  debugFlag = true;
};
/* eslint-enable */

@Dependencies(Config, Logger) //eslint-disable-line new-cap
export default class HttpClient extends ServiceInterface {
  /**
   * @param config {Config}
   * @param logger {Logger}
   */
  constructor(config, logger) {
    super();
    this.config = config.get();
    this.client = request;
    requestDebug(logger);
  }

  getProto() {
    return request;
  }
github IdleLands / IdleLands3 / src / plugins / players / player.js View on Github external
import { ItemGenerator } from '../../shared/item-generator';
import { MonsterGenerator } from '../../shared/monster-generator';
import { ShopGenerator } from '../../shared/shop-generator';

import { DataUpdater } from '../../shared/data-updater';
import { EventHandler } from '../events/eventhandler';
import { FindItem } from '../events/events/FindItem';

import * as Events from '../events/events/_all';
import * as Achievements from '../achievements/achievements/_all';

import { DirtyChecker } from './player.dirtychecker';

import { emitter } from './_emitter';

@Dependencies(PlayerDb)
export class Player extends Character {
  constructor(playerDb) {
    super();
    this.$playerDb = playerDb;
    this.$playerMovement = PlayerMovement;
    this.$itemGenerator = ItemGenerator;
    this.$dataUpdater = DataUpdater;
  }

  init(opts, save = true) {
    this.$dirty = new DirtyChecker();
    this.$canSave = save;

    super.init(opts);

    if(!this.joinDate)  this.joinDate = Date.now();
github EvaEngine / EvaEngine.js / src / services / redis.js View on Github external
import Ioredis from 'ioredis';
import { Dependencies } from 'constitute';
import Config from './config';
import ServiceInterface from './interface';

let redisClient = null;

@Dependencies(Config) //eslint-disable-line new-cap
export default class Redis extends ServiceInterface {
  /**
   * @param config Config
   */
  constructor(config) {
    super();
    this.config = config;
    this.options = null;
  }

  getProto() {
    return Ioredis;
  }

  getRedis() {
    return Ioredis;
github EvaEngine / EvaEngine.js / src / services / cache.js View on Github external
}

  set(key, value, minutes) {
    return minutes ?
      this.redis
        .set(this.key(key), JSON.stringify(value), 'ex', minutes * 60) :
      this.redis
        .set(this.key(key), JSON.stringify(value));
  }

  flush() {
    return this.redis.flushall();
  }
}

@Dependencies(Config, Redis) //eslint-disable-line new-cap
export default class Cache extends ServiceInterface {
  constructor(config) {
    super();
    this.config = config.get('cache');
    this.prefix = this.config.prefix || 'eva';
    this.driver = this.config.driver;
    this.store = null;
  }

  setStore(store) {
    this.store = store;
    return this;
  }

  /**
   * @returns {Store}
github EvaEngine / EvaEngine.js / src / services / namespace.js View on Github external
getContext() {
    return getNamespace(this.name);
  }

  createContext() {
    return getNamespace(this.name).createContext();
  }

  reset() {
    reset(this.name);
    return this;
  }
}

@Dependencies(Config) //eslint-disable-line new-cap
export default class Namespace extends ServiceInterface {
  /**
   * @param config {Config}
   */
  constructor(config) {
    super();
    this.config = config.get('namespace');
    this.defaultName = config.defaultName || 'eva.ns';
    this.store = null;
    this.name = null;
  }

  isEnabled() {
    return this.config.enable;
  }
github EvaEngine / EvaEngine.js / src / services / jwt_token.js View on Github external
import { Dependencies } from 'constitute';
import jwt from 'jwt-simple';
import Config from './config';
import Redis from './redis';
import ServiceInterface from './interface';

@Dependencies(Config, Redis) //eslint-disable-line new-cap
export default class JsonWebToken extends ServiceInterface {
  /**
   * @param config {Config}
   * @param redis {Redis}
   */
  constructor(config, redis) {
    super();
    this.redis = redis.getInstance();
    this.config = config.get('token');
  }

  getProto() {
    return jwt;
  }

  getRedis() {
github EvaEngine / EvaEngine.js / src / services / logger.js View on Github external
import { Dependencies } from 'constitute';
import moment from 'moment-timezone';
import winston from 'winston';
import { inspect } from 'util';
import Env from './env';
import Config from './config';
import Namespace from './namespace';
import ServiceInterface from './interface';


@Dependencies(Env, Config, Namespace) //eslint-disable-line new-cap
export default class Logger extends ServiceInterface {
  /**
   * @param env {Env}
   * @param config {Config}
   * @param namespace {Namespace}
   */
  constructor(env, config, namespace) {
    super();
    this.env = env;
    this.config = config;
    this.namespace = namespace;

    let level = env.isProduction() ? 'info' : 'debug';
    if (process.env.LOG_LEVEL) {
      level = process.env.LOG_LEVEL;
    }
github EvaEngine / EvaEngine.js / src / services / config.js View on Github external
import _ from 'lodash';
import { Dependencies } from 'constitute';
import springConfigClient from 'cloud-config-client';
import Env from './env';
import EngineConfig from '../config';
import ServiceInterface from './interface';

let config = null;

@Dependencies(Env) //eslint-disable-line new-cap
export default class Config extends ServiceInterface {
  /**
   * @param env {Env}
   */
  constructor(env) {
    super();
    this.env = env;
    this.path = null;
    this.mergedFiles = [];
  }

  setPath(path) {
    this.path = path;
    return this;
  }
github EvaEngine / EvaEngine.js / src / services / rest_client.js View on Github external
import { Dependencies } from 'constitute';
import HttpClient from './http_client';
import Namespace from './namespace';
import { RestServiceLogicException, RestServiceIOException } from '../exceptions';
import ServiceInterface from './interface';

@Dependencies(HttpClient, Namespace) //eslint-disable-line new-cap
export default class RestClient extends ServiceInterface {
  /**
   * @param {HttpClient} client
   * @param {Namespace} ns
   */
  constructor(client, ns) {
    super();
    this.client = client;
    this.ns = ns;
    this.baseUrl = null;
  }

  setBaseUrl(baseUrl) {
    this.baseUrl = baseUrl;
    return this;
  }

constitute

Minimalistic Dependency Injection (DI) for ES6

ISC
Latest version published 9 years ago

Package Health Score

51 / 100
Full package analysis

Popular constitute functions