UNPKG

inversify

Version:

A powerful and lightweight inversion of control container for JavaScript and Node.js apps powered by TypeScript.

90 lines (89 loc) 4.48 kB
"use strict"; var binding_on_syntax_1 = require("./binding_on_syntax"); var constraint_helpers_1 = require("./constraint_helpers"); var BindingWhenSyntax = (function () { function BindingWhenSyntax(binding) { this._binding = binding; } BindingWhenSyntax.prototype.when = function (constraint) { this._binding.constraint = constraint; return new binding_on_syntax_1.default(this._binding); }; BindingWhenSyntax.prototype.whenTargetNamed = function (name) { this._binding.constraint = constraint_helpers_1.namedConstraint(name); return new binding_on_syntax_1.default(this._binding); }; BindingWhenSyntax.prototype.whenTargetTagged = function (tag, value) { this._binding.constraint = constraint_helpers_1.taggedConstraint(tag)(value); return new binding_on_syntax_1.default(this._binding); }; BindingWhenSyntax.prototype.whenInjectedInto = function (parent) { this._binding.constraint = function (request) { return constraint_helpers_1.typeConstraint(parent)(request.parentRequest); }; return new binding_on_syntax_1.default(this._binding); }; BindingWhenSyntax.prototype.whenParentNamed = function (name) { this._binding.constraint = function (request) { return constraint_helpers_1.namedConstraint(name)(request.parentRequest); }; return new binding_on_syntax_1.default(this._binding); }; BindingWhenSyntax.prototype.whenParentTagged = function (tag, value) { this._binding.constraint = function (request) { return constraint_helpers_1.taggedConstraint(tag)(value)(request.parentRequest); }; return new binding_on_syntax_1.default(this._binding); }; BindingWhenSyntax.prototype.whenAnyAncestorIs = function (ancestor) { this._binding.constraint = function (request) { return constraint_helpers_1.traverseAncerstors(request, constraint_helpers_1.typeConstraint(ancestor)); }; return new binding_on_syntax_1.default(this._binding); }; BindingWhenSyntax.prototype.whenNoAncestorIs = function (ancestor) { this._binding.constraint = function (request) { return !constraint_helpers_1.traverseAncerstors(request, constraint_helpers_1.typeConstraint(ancestor)); }; return new binding_on_syntax_1.default(this._binding); }; BindingWhenSyntax.prototype.whenAnyAncestorNamed = function (name) { this._binding.constraint = function (request) { return constraint_helpers_1.traverseAncerstors(request, constraint_helpers_1.namedConstraint(name)); }; return new binding_on_syntax_1.default(this._binding); }; BindingWhenSyntax.prototype.whenNoAncestorNamed = function (name) { this._binding.constraint = function (request) { return !constraint_helpers_1.traverseAncerstors(request, constraint_helpers_1.namedConstraint(name)); }; return new binding_on_syntax_1.default(this._binding); }; BindingWhenSyntax.prototype.whenAnyAncestorTagged = function (tag, value) { this._binding.constraint = function (request) { return constraint_helpers_1.traverseAncerstors(request, constraint_helpers_1.taggedConstraint(tag)(value)); }; return new binding_on_syntax_1.default(this._binding); }; BindingWhenSyntax.prototype.whenNoAncestorTagged = function (tag, value) { this._binding.constraint = function (request) { return !constraint_helpers_1.traverseAncerstors(request, constraint_helpers_1.taggedConstraint(tag)(value)); }; return new binding_on_syntax_1.default(this._binding); }; BindingWhenSyntax.prototype.whenAnyAncestorMatches = function (constraint) { this._binding.constraint = function (request) { return constraint_helpers_1.traverseAncerstors(request, constraint); }; return new binding_on_syntax_1.default(this._binding); }; BindingWhenSyntax.prototype.whenNoAncestorMatches = function (constraint) { this._binding.constraint = function (request) { return !constraint_helpers_1.traverseAncerstors(request, constraint); }; return new binding_on_syntax_1.default(this._binding); }; return BindingWhenSyntax; }()); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = BindingWhenSyntax;