Simplify names, have modules return byName
This commit is contained in:
parent
e66af1e1d2
commit
b59c919733
|
@ -8,12 +8,16 @@
|
||||||
* LICENSE file in the root directory of this source tree.
|
* LICENSE file in the root directory of this source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Modules } from './modules';
|
import { Module, Modules } from './modules';
|
||||||
import { Reflection as DOM } from 'ui';
|
import { Reflection as DOM } from 'ui';
|
||||||
import Resolver from './resolver';
|
import Resolver from './resolver';
|
||||||
|
|
||||||
export default class Reflection {
|
export default class Reflection {
|
||||||
|
|
||||||
|
static get module() {
|
||||||
|
return Module;
|
||||||
|
}
|
||||||
|
|
||||||
static get modules() {
|
static get modules() {
|
||||||
return Modules;
|
return Modules;
|
||||||
}
|
}
|
||||||
|
|
|
@ -184,7 +184,7 @@ const KnownModules = {
|
||||||
ExternalLink: Filters.byCode(/\.trusted\b/)
|
ExternalLink: Filters.byCode(/\.trusted\b/)
|
||||||
};
|
};
|
||||||
|
|
||||||
class Modules {
|
class Module {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds a module using a filter function.
|
* Finds a module using a filter function.
|
||||||
|
@ -218,7 +218,7 @@ class Modules {
|
||||||
* @param {Function} fallback A function to use to filter modules if not finding a known module
|
* @param {Function} fallback A function to use to filter modules if not finding a known module
|
||||||
* @return {Any}
|
* @return {Any}
|
||||||
*/
|
*/
|
||||||
static getModuleByName(name, fallback) {
|
static byName(name, fallback) {
|
||||||
if (Cache.hasOwnProperty(name)) return Cache[name];
|
if (Cache.hasOwnProperty(name)) return Cache[name];
|
||||||
if (KnownModules.hasOwnProperty(name)) fallback = KnownModules[name];
|
if (KnownModules.hasOwnProperty(name)) fallback = KnownModules[name];
|
||||||
if (!fallback) return undefined;
|
if (!fallback) return undefined;
|
||||||
|
@ -231,7 +231,7 @@ class Modules {
|
||||||
* @param {String} name The display name of the module
|
* @param {String} name The display name of the module
|
||||||
* @return {Any}
|
* @return {Any}
|
||||||
*/
|
*/
|
||||||
static getModuleByDisplayName(name) {
|
static byDisplayName(name) {
|
||||||
return this.getModule(Filters.byDisplayName(name), true);
|
return this.getModule(Filters.byDisplayName(name), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -241,7 +241,7 @@ class Modules {
|
||||||
* @param {Boolean} first Whether to return the only the first matching module
|
* @param {Boolean} first Whether to return the only the first matching module
|
||||||
* @return {Any}
|
* @return {Any}
|
||||||
*/
|
*/
|
||||||
static getModuleByRegex(regex, first = true) {
|
static byRegex(regex, first = true) {
|
||||||
return this.getModule(Filters.byCode(regex), first);
|
return this.getModule(Filters.byCode(regex), first);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -251,7 +251,7 @@ class Modules {
|
||||||
* @param {Boolean} first Whether to return only the first matching module
|
* @param {Boolean} first Whether to return only the first matching module
|
||||||
* @return {Any}
|
* @return {Any}
|
||||||
*/
|
*/
|
||||||
static getModuleByPrototypes(prototypes, first = true) {
|
static byPrototypes(prototypes, first = true) {
|
||||||
return this.getModule(Filters.byPrototypeFields(prototypes), first);
|
return this.getModule(Filters.byPrototypeFields(prototypes), first);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -261,7 +261,7 @@ class Modules {
|
||||||
* @param {Boolean} first Whether to return only the first matching module
|
* @param {Boolean} first Whether to return only the first matching module
|
||||||
* @return {Any}
|
* @return {Any}
|
||||||
*/
|
*/
|
||||||
static getModuleByProps(props, first = true) {
|
static byProps(props, first = true) {
|
||||||
return this.getModule(Filters.byProperties(props), first);
|
return this.getModule(Filters.byProperties(props), first);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -408,10 +408,10 @@ class Modules {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const ModuleProxy = new Proxy(Modules, {
|
const Modules = new Proxy(Module, {
|
||||||
get(Modules, property) {
|
get(Module, name) {
|
||||||
return Modules[property] || Modules.getModuleByName(property);
|
return Module.byName(name);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
export { ModuleProxy as Modules };
|
export { Module, Modules }
|
||||||
|
|
Loading…
Reference in New Issue