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

dependency-inject

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dependency-inject - npm Package Compare versions

Comparing version 1.0.4 to 1.0.5

.babelrc

84

built/all.test.js
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var __decorate = undefined && undefined.__decorate || function (decorators, target, key, desc) {
var c = arguments.length,
r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
d;
if ((typeof Reflect === "undefined" ? "undefined" : _typeof(Reflect)) === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);else for (var i = decorators.length - 1; i >= 0; i--) {
if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
}return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
var __metadata = undefined && undefined.__metadata || function (k, v) {
if ((typeof Reflect === "undefined" ? "undefined" : _typeof(Reflect)) === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
const ava_1 = require("ava");
const index_1 = require("./index");
class Store {
constructor() {
this.num = 1;
var ava_1 = require("ava");
var index_1 = require("./index");
var Store = function Store() {
_classCallCheck(this, Store);
this.num = 1;
};
var Action = function () {
function Action() {
_classCallCheck(this, Action);
}
}
class Action {
setNum(num) {
this.store.num = num;
}
}
__decorate([
index_1.inject(Store),
__metadata("design:type", Store)
], Action.prototype, "store", void 0);
ava_1.default('can be injected', t => {
const container = new index_1.Container();
_createClass(Action, [{
key: "setNum",
value: function setNum(num) {
this.store.num = num;
}
}]);
return Action;
}();
__decorate([index_1.inject(Store), __metadata("design:type", Store)], Action.prototype, "store", void 0);
ava_1.default('can be injected', function (t) {
var container = new index_1.Container();
container.set(Store, new Store());
container.set(Action, new Action());
const store = container.get(Store);
const action = container.get(Action);
var store = container.get(Store);
var action = container.get(Action);
action.setNum(2);
t.true(store.num === 2);
});
ava_1.default('No interference between instances', t => {
const containerA = new index_1.Container();
ava_1.default('No interference between instances', function (t) {
var containerA = new index_1.Container();
containerA.set(Store, new Store());
containerA.set(Action, new Action());
const actionA = containerA.get(Action);
const storeA = containerA.get(Store);
const containerB = new index_1.Container();
var actionA = containerA.get(Action);
var storeA = containerA.get(Store);
var containerB = new index_1.Container();
containerB.set(Store, new Store());
containerB.set(Action, new Action());
const actionB = containerB.get(Action);
const storeB = containerB.get(Store);
var actionB = containerB.get(Action);
var storeB = containerB.get(Store);
actionB.setNum(3);

@@ -49,0 +67,0 @@ t.true(storeA.num === 1);

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

@@ -3,0 +4,0 @@ var container_1 = require("./src/container");

"use strict";
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
Object.defineProperty(exports, "__esModule", { value: true });
const handlers_1 = require("./handlers");
class Container {
constructor() {
var handlers_1 = require("./handlers");
var Container = function () {
function Container() {
_classCallCheck(this, Container);
this.instances = new WeakMap();
}
set(setClass, instance) {
if (!this.instances.has(setClass)) {
this.instances.set(setClass, instance);
_createClass(Container, [{
key: "set",
value: function set(setClass, instance) {
if (!this.instances.has(setClass)) {
this.instances.set(setClass, instance);
}
}
}
get(getClass) {
if (!this.instances.has(getClass)) {
throw new Error(`${getClass.name} 未注册。先使用 set 方法注册,再使用 get 获取`);
}
const instance = this.instances.get(getClass);
if (!instance[handlers_1.injectSymbol]) {
}, {
key: "get",
value: function get(getClass) {
var _this = this;
if (!this.instances.has(getClass)) {
throw new Error(getClass.name + " \u672A\u6CE8\u518C\u3002\u5148\u4F7F\u7528 set \u65B9\u6CD5\u6CE8\u518C\uFF0C\u518D\u4F7F\u7528 get \u83B7\u53D6");
}
var instance = this.instances.get(getClass);
if (!instance[handlers_1.injectSymbol]) {
return instance;
}
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
var _loop = function _loop() {
var _step$value = _slicedToArray(_step.value, 2),
propertyKey = _step$value[0],
injectClass = _step$value[1];
Object.defineProperty(instance, propertyKey, {
enumerable: true,
configurable: true,
get: function get() {
return _this.instances.get(injectClass);
},
set: function set(newValue) {
instance.propertyKey = newValue;
}
});
};
for (var _iterator = instance[handlers_1.injectSymbol][Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
_loop();
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
return instance;
}
for (let [propertyKey, injectClass] of instance[handlers_1.injectSymbol]) {
Object.defineProperty(instance, propertyKey, {
enumerable: true,
configurable: true,
get: () => {
return this.instances.get(injectClass);
},
set: (newValue) => {
instance.propertyKey = newValue;
}
});
}
return instance;
}
}
}]);
return Container;
}();
exports.default = Container;
//# sourceMappingURL=container.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const handlers_1 = require("./handlers");
exports.default = (injectClass) => (target, propertyKey) => {
if (!target[handlers_1.injectSymbol]) {
target[handlers_1.injectSymbol] = new Map();
}
target[handlers_1.injectSymbol].set(propertyKey, injectClass);
var handlers_1 = require("./handlers");
exports.default = function (injectClass) {
return function (target, propertyKey) {
if (!target[handlers_1.injectSymbol]) {
target[handlers_1.injectSymbol] = new Map();
}
target[handlers_1.injectSymbol].set(propertyKey, injectClass);
};
};
//# sourceMappingURL=decorators.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.injectSymbol = Symbol();
//# sourceMappingURL=handlers.js.map
{
"name": "dependency-inject",
"version": "1.0.4",
"version": "1.0.5",
"description": "",

@@ -8,3 +8,3 @@ "main": "built/index.js",

"test": "tsc && ava",
"prepublish": "tsc"
"prepublish": "rm -rf built && tsc && babel built --out-dir built"
},

@@ -28,4 +28,7 @@ "ava": {

"ava": "^0.18.2",
"typescript": "^2.2.1"
"typescript": "^2.2.1",
"babel-cli": "^6.24.0",
"babel-preset-es2015": "^6.24.0",
"babel-preset-stage-0": "^6.22.0"
}
}

Sorry, the diff of this file is not supported yet

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