UNPKG

@jable/inject

Version:

Inject dependencies into injectable classes

66 lines (65 loc) 2.4 kB
"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 __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; Object.defineProperty(exports, "__esModule", { value: true }); var injectable_decorator_1 = require("../injectable.decorator"); var Bar = /** @class */ (function () { function Bar(p1) { if (p1 === void 0) { p1 = "bye"; } this.p1 = p1; } Bar = __decorate([ injectable_decorator_1.Injectable(), __metadata("design:paramtypes", [String]) ], Bar); return Bar; }()); exports.Bar = Bar; var Foo = /** @class */ (function () { function Foo(bar) { this.bar = bar; } Foo = __decorate([ injectable_decorator_1.Injectable(), __metadata("design:paramtypes", [Bar]) ], Foo); return Foo; }()); exports.Foo = Foo; var FinalInject = /** @class */ (function () { function FinalInject(foo) { this.foo = foo; } FinalInject = __decorate([ injectable_decorator_1.Injectable(), __metadata("design:paramtypes", [Foo]) ], FinalInject); return FinalInject; }()); exports.FinalInject = FinalInject; var Injecting = /** @class */ (function () { function Injecting(foo, bar) { this.foo = foo; this.bar = bar; } Injecting = __decorate([ injectable_decorator_1.Injectable({ exclude: { 'BooBoo.Bar': true } }), __metadata("design:paramtypes", [FinalInject, Bar]) ], Injecting); return Injecting; }()); var inj = new Injecting(); console.log(inj.foo.foo.bar.p1); inj.foo.foo.bar.p1 = "hi"; var inj2 = new Injecting(new Bar()); console.log(inj2.foo.foo.bar.p1); console.log(inj2.bar.p1);