src/lib/binding.js
import {ResolvedBinding} from './resolvedBinding'
/**
* @class Binding
*/
export class Binding{
/**
* This is a Binding
* @constructor
* @param {String} token - This is the token of the Binding
* @param {Object} object - This if the object concerned, can be toClass, toValue, toFactory
*/
constructor(token, object){
this.token = token;
this.object = object;
}
/**
* Create a ResolvedBinding from the current Binding
* @returns {ResolvedBinding} The resolvedBinding generated
*/
resolve(){
let factory = null;
let deps = null;
if(this.object){
deps = this.object.deps;
if(this.object.toClass){
factory = (a,b,c,d,e,f,g,h,i,j)=>{
return new this.object.toClass(a,b,c,d,e,f,g,h,i,j);
}
}else{
if(this.object.toFactory){
factory = this.object.toFactory
}else{
if(this.object.toValue){
factory = () =>{
return this.object.toValue
}
}
}
}
}else{
factory = ()=>{
return null;
}
}
return new ResolvedBinding(this.token, factory, deps);
}
}