diff options
author | Minteck <contact@minteck.org> | 2021-12-21 16:52:28 +0100 |
---|---|---|
committer | Minteck <contact@minteck.org> | 2021-12-21 16:52:28 +0100 |
commit | 46e43f4bde4a35785b4997b81e86cd19f046b69b (patch) | |
tree | c53c2f826f777f9d6b2d249dab556feb72a6c3a6 /src/node_modules/inversify/amd/syntax/binding_to_syntax.js | |
download | langdetect-46e43f4bde4a35785b4997b81e86cd19f046b69b.tar.gz langdetect-46e43f4bde4a35785b4997b81e86cd19f046b69b.tar.bz2 langdetect-46e43f4bde4a35785b4997b81e86cd19f046b69b.zip |
Commit
Diffstat (limited to 'src/node_modules/inversify/amd/syntax/binding_to_syntax.js')
-rw-r--r-- | src/node_modules/inversify/amd/syntax/binding_to_syntax.js | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/src/node_modules/inversify/amd/syntax/binding_to_syntax.js b/src/node_modules/inversify/amd/syntax/binding_to_syntax.js new file mode 100644 index 0000000..b6e08f5 --- /dev/null +++ b/src/node_modules/inversify/amd/syntax/binding_to_syntax.js @@ -0,0 +1,71 @@ +define(["require", "exports", "../constants/error_msgs", "../constants/literal_types", "./binding_in_when_on_syntax", "./binding_when_on_syntax"], function (require, exports, ERROR_MSGS, literal_types_1, binding_in_when_on_syntax_1, binding_when_on_syntax_1) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + var BindingToSyntax = (function () { + function BindingToSyntax(binding) { + this._binding = binding; + } + BindingToSyntax.prototype.to = function (constructor) { + this._binding.type = literal_types_1.BindingTypeEnum.Instance; + this._binding.implementationType = constructor; + return new binding_in_when_on_syntax_1.BindingInWhenOnSyntax(this._binding); + }; + BindingToSyntax.prototype.toSelf = function () { + if (typeof this._binding.serviceIdentifier !== "function") { + throw new Error("" + ERROR_MSGS.INVALID_TO_SELF_VALUE); + } + var self = this._binding.serviceIdentifier; + return this.to(self); + }; + BindingToSyntax.prototype.toConstantValue = function (value) { + this._binding.type = literal_types_1.BindingTypeEnum.ConstantValue; + this._binding.cache = value; + this._binding.dynamicValue = null; + this._binding.implementationType = null; + return new binding_when_on_syntax_1.BindingWhenOnSyntax(this._binding); + }; + BindingToSyntax.prototype.toDynamicValue = function (func) { + this._binding.type = literal_types_1.BindingTypeEnum.DynamicValue; + this._binding.cache = null; + this._binding.dynamicValue = func; + this._binding.implementationType = null; + return new binding_in_when_on_syntax_1.BindingInWhenOnSyntax(this._binding); + }; + BindingToSyntax.prototype.toConstructor = function (constructor) { + this._binding.type = literal_types_1.BindingTypeEnum.Constructor; + this._binding.implementationType = constructor; + return new binding_when_on_syntax_1.BindingWhenOnSyntax(this._binding); + }; + BindingToSyntax.prototype.toFactory = function (factory) { + this._binding.type = literal_types_1.BindingTypeEnum.Factory; + this._binding.factory = factory; + return new binding_when_on_syntax_1.BindingWhenOnSyntax(this._binding); + }; + BindingToSyntax.prototype.toFunction = function (func) { + if (typeof func !== "function") { + throw new Error(ERROR_MSGS.INVALID_FUNCTION_BINDING); + } + var bindingWhenOnSyntax = this.toConstantValue(func); + this._binding.type = literal_types_1.BindingTypeEnum.Function; + return bindingWhenOnSyntax; + }; + BindingToSyntax.prototype.toAutoFactory = function (serviceIdentifier) { + this._binding.type = literal_types_1.BindingTypeEnum.Factory; + this._binding.factory = function (context) { + var autofactory = function () { return context.container.get(serviceIdentifier); }; + return autofactory; + }; + return new binding_when_on_syntax_1.BindingWhenOnSyntax(this._binding); + }; + BindingToSyntax.prototype.toProvider = function (provider) { + this._binding.type = literal_types_1.BindingTypeEnum.Provider; + this._binding.provider = provider; + return new binding_when_on_syntax_1.BindingWhenOnSyntax(this._binding); + }; + BindingToSyntax.prototype.toService = function (service) { + this.toDynamicValue(function (context) { return context.container.get(service); }); + }; + return BindingToSyntax; + }()); + exports.BindingToSyntax = BindingToSyntax; +}); |