@ima/core
Version:
IMA.js framework for isomorphic javascript application
73 lines (72 loc) • 2.32 kB
JavaScript
/**
* Object container entry, representing either a class, interface, constant or
* an alias.
*/ export class Entry {
/**
* The constructor of the class represented by this entry, or the
* getter of the value of the constant represented by this entry.
*/ classConstructor;
/**
* The shared instance of the class represented by this entry.
*/ sharedInstance = null;
/**
* Dependencies of the class constructor of the class represented by
* this entry.
*/ #dependencies;
/**
* The Entry options.
*/ #options;
/**
* The override counter
*/ #overrideCounter = 0;
/**
* Reference to part of application that created
* this entry.
*/ #referrer;
/**
* Initializes the entry.
*
* @param classConstructor The
* class constructor or constant value getter.
* @param dependencies The dependencies to pass into the
* constructor function.
* @param referrer Reference to part of application that created
* this entry.
* @param options The Entry options.
*/ constructor(classConstructor, dependencies, referrer, options){
this.classConstructor = classConstructor;
this.#referrer = referrer;
this.#dependencies = dependencies || [];
this.#options = options || {
writeable: true
};
}
set dependencies(dependencies) {
if ($Debug) {
if (!this.writeable) {
throw new Error(`The entry is constant and you ` + `can't redefined their dependencies ${dependencies}.`);
}
if (this.#overrideCounter >= 1) {
throw new Error(`The dependencies entry can't be overridden more than once.` + `Fix your bind.js file for classConstructor ${this.classConstructor.name}.`);
}
}
this.#dependencies = dependencies;
this.#overrideCounter++;
}
get dependencies() {
return this.#dependencies;
}
get referrer() {
return this.#referrer;
}
get writeable() {
return this.#options.writeable;
}
get options() {
return this.#options;
}
static from(entry) {
return new Entry(entry.classConstructor, entry.dependencies, entry.referrer, entry.options);
}
}
//# sourceMappingURL=Entry.js.map