1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.BindingWhenSyntax = void 0;
|
4 | var binding_on_syntax_1 = require("./binding_on_syntax");
|
5 | var constraint_helpers_1 = require("./constraint_helpers");
|
6 | var BindingWhenSyntax = (function () {
|
7 | function BindingWhenSyntax(binding) {
|
8 | this._binding = binding;
|
9 | }
|
10 | BindingWhenSyntax.prototype.when = function (constraint) {
|
11 | this._binding.constraint = constraint;
|
12 | return new binding_on_syntax_1.BindingOnSyntax(this._binding);
|
13 | };
|
14 | BindingWhenSyntax.prototype.whenTargetNamed = function (name) {
|
15 | this._binding.constraint = (0, constraint_helpers_1.namedConstraint)(name);
|
16 | return new binding_on_syntax_1.BindingOnSyntax(this._binding);
|
17 | };
|
18 | BindingWhenSyntax.prototype.whenTargetIsDefault = function () {
|
19 | this._binding.constraint = function (request) {
|
20 | if (request === null) {
|
21 | return false;
|
22 | }
|
23 | var targetIsDefault = (request.target !== null) &&
|
24 | (!request.target.isNamed()) &&
|
25 | (!request.target.isTagged());
|
26 | return targetIsDefault;
|
27 | };
|
28 | return new binding_on_syntax_1.BindingOnSyntax(this._binding);
|
29 | };
|
30 | BindingWhenSyntax.prototype.whenTargetTagged = function (tag, value) {
|
31 | this._binding.constraint = (0, constraint_helpers_1.taggedConstraint)(tag)(value);
|
32 | return new binding_on_syntax_1.BindingOnSyntax(this._binding);
|
33 | };
|
34 | BindingWhenSyntax.prototype.whenInjectedInto = function (parent) {
|
35 | this._binding.constraint = function (request) {
|
36 | return request !== null && (0, constraint_helpers_1.typeConstraint)(parent)(request.parentRequest);
|
37 | };
|
38 | return new binding_on_syntax_1.BindingOnSyntax(this._binding);
|
39 | };
|
40 | BindingWhenSyntax.prototype.whenParentNamed = function (name) {
|
41 | this._binding.constraint = function (request) {
|
42 | return request !== null && (0, constraint_helpers_1.namedConstraint)(name)(request.parentRequest);
|
43 | };
|
44 | return new binding_on_syntax_1.BindingOnSyntax(this._binding);
|
45 | };
|
46 | BindingWhenSyntax.prototype.whenParentTagged = function (tag, value) {
|
47 | this._binding.constraint = function (request) {
|
48 | return request !== null && (0, constraint_helpers_1.taggedConstraint)(tag)(value)(request.parentRequest);
|
49 | };
|
50 | return new binding_on_syntax_1.BindingOnSyntax(this._binding);
|
51 | };
|
52 | BindingWhenSyntax.prototype.whenAnyAncestorIs = function (ancestor) {
|
53 | this._binding.constraint = function (request) {
|
54 | return request !== null && (0, constraint_helpers_1.traverseAncerstors)(request, (0, constraint_helpers_1.typeConstraint)(ancestor));
|
55 | };
|
56 | return new binding_on_syntax_1.BindingOnSyntax(this._binding);
|
57 | };
|
58 | BindingWhenSyntax.prototype.whenNoAncestorIs = function (ancestor) {
|
59 | this._binding.constraint = function (request) {
|
60 | return request !== null && !(0, constraint_helpers_1.traverseAncerstors)(request, (0, constraint_helpers_1.typeConstraint)(ancestor));
|
61 | };
|
62 | return new binding_on_syntax_1.BindingOnSyntax(this._binding);
|
63 | };
|
64 | BindingWhenSyntax.prototype.whenAnyAncestorNamed = function (name) {
|
65 | this._binding.constraint = function (request) {
|
66 | return request !== null && (0, constraint_helpers_1.traverseAncerstors)(request, (0, constraint_helpers_1.namedConstraint)(name));
|
67 | };
|
68 | return new binding_on_syntax_1.BindingOnSyntax(this._binding);
|
69 | };
|
70 | BindingWhenSyntax.prototype.whenNoAncestorNamed = function (name) {
|
71 | this._binding.constraint = function (request) {
|
72 | return request !== null && !(0, constraint_helpers_1.traverseAncerstors)(request, (0, constraint_helpers_1.namedConstraint)(name));
|
73 | };
|
74 | return new binding_on_syntax_1.BindingOnSyntax(this._binding);
|
75 | };
|
76 | BindingWhenSyntax.prototype.whenAnyAncestorTagged = function (tag, value) {
|
77 | this._binding.constraint = function (request) {
|
78 | return request !== null && (0, constraint_helpers_1.traverseAncerstors)(request, (0, constraint_helpers_1.taggedConstraint)(tag)(value));
|
79 | };
|
80 | return new binding_on_syntax_1.BindingOnSyntax(this._binding);
|
81 | };
|
82 | BindingWhenSyntax.prototype.whenNoAncestorTagged = function (tag, value) {
|
83 | this._binding.constraint = function (request) {
|
84 | return request !== null && !(0, constraint_helpers_1.traverseAncerstors)(request, (0, constraint_helpers_1.taggedConstraint)(tag)(value));
|
85 | };
|
86 | return new binding_on_syntax_1.BindingOnSyntax(this._binding);
|
87 | };
|
88 | BindingWhenSyntax.prototype.whenAnyAncestorMatches = function (constraint) {
|
89 | this._binding.constraint = function (request) {
|
90 | return request !== null && (0, constraint_helpers_1.traverseAncerstors)(request, constraint);
|
91 | };
|
92 | return new binding_on_syntax_1.BindingOnSyntax(this._binding);
|
93 | };
|
94 | BindingWhenSyntax.prototype.whenNoAncestorMatches = function (constraint) {
|
95 | this._binding.constraint = function (request) {
|
96 | return request !== null && !(0, constraint_helpers_1.traverseAncerstors)(request, constraint);
|
97 | };
|
98 | return new binding_on_syntax_1.BindingOnSyntax(this._binding);
|
99 | };
|
100 | return BindingWhenSyntax;
|
101 | }());
|
102 | exports.BindingWhenSyntax = BindingWhenSyntax;
|