Fix resolver and add helpers to it
This commit is contained in:
parent
32fc655326
commit
5c493d413b
|
@ -22,6 +22,14 @@ export default class Reflection {
|
||||||
return Modules;
|
return Modules;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static get resolve() {
|
||||||
|
return Resolver.resolve;
|
||||||
|
}
|
||||||
|
|
||||||
|
static get resolveAsync() {
|
||||||
|
return Resolver.resolveAsync;
|
||||||
|
}
|
||||||
|
|
||||||
static get resolver() {
|
static get resolver() {
|
||||||
return Resolver;
|
return Resolver;
|
||||||
}
|
}
|
||||||
|
@ -29,5 +37,4 @@ export default class Reflection {
|
||||||
static get DOM() {
|
static get DOM() {
|
||||||
return DOM;
|
return DOM;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,9 +8,35 @@
|
||||||
* 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 } from './modules';
|
||||||
|
|
||||||
export class Resolver {
|
class Resolved {
|
||||||
|
|
||||||
|
constructor(module, ...classes) {
|
||||||
|
this.module = Module.byProps(...classes);
|
||||||
|
this.classes = classes;
|
||||||
|
}
|
||||||
|
|
||||||
|
get className() {
|
||||||
|
return this.module && this.module[this.classes[0]] ? this.module[this.classes[0]].split(' ')[0] : this.classes[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
get selector() {
|
||||||
|
return `.${this.className}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class Resolver {
|
||||||
|
|
||||||
|
static resolve(...classes) {
|
||||||
|
return new Resolved(Module.byProps(...classes), ...classes);
|
||||||
|
}
|
||||||
|
|
||||||
|
static async resolveAsync(...classes) {
|
||||||
|
const module = await Module.waitForModuleByProps([...classes]);
|
||||||
|
return new Resolved(module, ...classes);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Searches for a class module and returns a class from it.
|
* Searches for a class module and returns a class from it.
|
||||||
|
@ -19,11 +45,11 @@ export class Resolver {
|
||||||
* @return {String}
|
* @return {String}
|
||||||
*/
|
*/
|
||||||
static getClassName(base, ...additional_classes) {
|
static getClassName(base, ...additional_classes) {
|
||||||
const class_module = Modules.getModuleByProps([base, ...additional_classes]);
|
const class_module = Module.byProps([base, ...additional_classes]);
|
||||||
if (class_module && class_module[base]) return class_module[base].split(' ')[0];
|
if (class_module && class_module[base]) return class_module[base].split(' ')[0];
|
||||||
}
|
}
|
||||||
static async waitForClassName(base, ...additional_classes) {
|
static async waitForClassName(base, ...additional_classes) {
|
||||||
const class_module = await Modules.waitForModuleByProps([base, ...additional_classes]);
|
const class_module = await Module.waitForModuleByProps([base, ...additional_classes]);
|
||||||
if (class_module && class_module[base]) return class_module[base].split(' ')[0];
|
if (class_module && class_module[base]) return class_module[base].split(' ')[0];
|
||||||
}
|
}
|
||||||
static getSelector(base, ...additional_classes) {
|
static getSelector(base, ...additional_classes) {
|
||||||
|
|
Loading…
Reference in New Issue