import { interfaces } from "../interfaces/interfaces" ; import { BindingOnSyntax } from "./binding_on_syntax" ; import { namedConstraint , taggedConstraint , traverseAncerstors , typeConstraint } from "./constraint_helpers" ; class BindingWhenSyntax < T > implements interfaces . BindingWhenSyntax < T > { private _binding : interfaces . Binding < T > ; public constructor ( binding ) { this . _binding = binding ; } public when ( constraint ) { this . _binding . constraint = constraint as interfaces . ConstraintFunction ; return new BindingOnSyntax < T > ( this . _binding ) ; } public whenTargetNamed ( name ) { this . _binding . constraint = namedConstraint ( name ) ; return new BindingOnSyntax < T > ( this . _binding ) ; } public whenTargetIsDefault ( ) { this . _binding . constraint = ( request ) => { if ( request === null ) { return false ; } const targetIsDefault = ( request . target !== null ) && ( ! request . target . isNamed ( ) ) && ( ! request . target . isTagged ( ) ) ; return targetIsDefault ; } ; return new BindingOnSyntax < T > ( this . _binding ) ; } public whenTargetTagged ( tag , value ) { this . _binding . constraint = taggedConstraint ( tag ) ( value ) ; return new BindingOnSyntax < T > ( this . _binding ) ; } public whenInjectedInto ( parent ) { this . _binding . constraint = ( request ) => request !== null && typeConstraint ( parent ) ( request . parentRequest ) ; return new BindingOnSyntax < T > ( this . _binding ) ; } public whenParentNamed ( name ) { this . _binding . constraint = ( request ) => request !== null && namedConstraint ( name ) ( request . parentRequest ) ; return new BindingOnSyntax < T > ( this . _binding ) ; } public whenParentTagged ( tag , value ) { this . _binding . constraint = ( request ) => request !== null && taggedConstraint ( tag ) ( value ) ( request . parentRequest ) ; return new BindingOnSyntax < T > ( this . _binding ) ; } public whenAnyAncestorIs ( ancestor ) { this . _binding . constraint = ( request ) => request !== null && traverseAncerstors ( request , typeConstraint ( ancestor ) ) ; return new BindingOnSyntax < T > ( this . _binding ) ; } public whenNoAncestorIs ( ancestor ) { this . _binding . constraint = ( request ) => request !== null && ! traverseAncerstors ( request , typeConstraint ( ancestor ) ) ; return new BindingOnSyntax < T > ( this . _binding ) ; } public whenAnyAncestorNamed ( name ) { this . _binding . constraint = ( request ) => request !== null && traverseAncerstors ( request , namedConstraint ( name ) ) ; return new BindingOnSyntax < T > ( this . _binding ) ; } public whenNoAncestorNamed ( name ) { this . _binding . constraint = ( request ) => request !== null && ! traverseAncerstors ( request , namedConstraint ( name ) ) ; return new BindingOnSyntax < T > ( this . _binding ) ; } public whenAnyAncestorTagged ( tag , value ) { this . _binding . constraint = ( request ) => request !== null && traverseAncerstors ( request , taggedConstraint ( tag ) ( value ) ) ; return new BindingOnSyntax < T > ( this . _binding ) ; } public whenNoAncestorTagged ( tag , value ) { this . _binding . constraint = ( request ) => request !== null && ! traverseAncerstors ( request , taggedConstraint ( tag ) ( value ) ) ; return new BindingOnSyntax < T > ( this . _binding ) ; } public whenAnyAncestorMatches ( constraint ) { this . _binding . constraint = ( request ) => request !== null && traverseAncerstors ( request , constraint as interfaces . ConstraintFunction ) ; return new BindingOnSyntax < T > ( this . _binding ) ; } public whenNoAncestorMatches ( constraint ) { this . _binding . constraint = ( request ) => request !== null && ! traverseAncerstors ( request , constraint as interfaces . ConstraintFunction ) ; return new BindingOnSyntax < T > ( this . _binding ) ; } } export { BindingWhenSyntax } ;