Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@loke/di-ioc

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@loke/di-ioc - npm Package Compare versions

Comparing version 2.0.0 to 2.0.1

73

lib/router.js

@@ -55,13 +55,4 @@ 'use strict';

init(options) {
const getters = this._initializeGetters();
if (options) {
Object.keys(options).forEach((key) => {
const value = options[key];
const getter = () => value;
getter.longName = '<parameter: ' + key + '>';
getters[key] = getter;
});
}
// TODO: I can't see why we have getters as well as container
const getters = this._initializeGetters(options);
return this._build(getters, []);

@@ -102,2 +93,15 @@ }

/**
* Gets the current definition (if any) matching name.
* Ignores interfaces.
* @param {any} name
* @returns
* @memberof Router
*/
get(name) {
const defs = this._defs.filter(item => (item.name === name && item.type !== TYPE_INTERFACE));
if (!defs.length) return null;
return defs[0];
}
/**
* Defines a new service with dependencies

@@ -134,2 +138,11 @@ * @param {String} type singleton, transient, etc

/**
* Adds a new definition to the set
* @param {Object} def
* @memberof Router
*/
add(def) {
this._defs.push(def);
}
unset(name) {

@@ -141,2 +154,17 @@ // Redefine the deps array, removing anything that matches the name.

/**
* Updates the current definition matching `name`.
*
* @param {any} name the name to match
* @param {any} patch
* @memberof Router
*
* @example router.update('myService', { type: 'singleton' })
*/
update(name, patch) {
const def = this.get(name);
this.unset(name);
this.add(Object.assign({}, def, patch));
}
clone() {

@@ -202,2 +230,4 @@ const theClone = Object.create(this);

// only allow existing if interface
// use .unset() to remove a definition
if (existing && !(existing instanceof Interface)) {

@@ -256,6 +286,6 @@ throw new Error('Re-definition of service ' + existing.longName.join('.') + ': ' + longName.join('.'));

_initializeGetters() {
const state = {};
_initializeGetters(options) {
const getters = {};
state.ioc = () => {
getters.ioc = () => {
return {

@@ -266,3 +296,3 @@ /**

get(name) {
return state[name]();
return getters[name]();
},

@@ -283,3 +313,3 @@ /**

if (state[name]) return state[name](local);
if (getters[name]) return getters[name](local);

@@ -294,3 +324,12 @@ throw new Error('Missing dependency: ' + name);

return state;
if (options) {
Object.keys(options).forEach((key) => {
const value = options[key];
const getter = () => value;
getter.longName = '<parameter: ' + key + '>';
getters[key] = getter;
});
}
return getters;
}

@@ -297,0 +336,0 @@

{
"name": "@loke/di-ioc",
"version": "2.0.0",
"version": "2.0.1",
"description": "Node.js dependency injection.",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc