@dark-engine/core
Version:
The lightweight and powerful UI rendering engine without dependencies and written in TypeScript (Browser, Node.js, Android, iOS, Windows, Linux, macOS)
33 lines (32 loc) • 1.15 kB
JavaScript
import { KEY_ATTR } from '../constants';
const $$inject = Symbol('inject');
class Component {
type = null;
props = null;
token = null;
displayName = null;
shouldUpdate = null;
children = null;
constructor(type, token, props, shouldUpdate, displayName) {
this.type = type;
this.props = props;
token && (this.token = token);
shouldUpdate && (this.shouldUpdate = shouldUpdate);
displayName && (this.displayName = displayName);
}
}
function component(type, options = {}) {
const { token: $token, displayName } = options;
const factory = (props = {}) => {
const { token = $token, shouldUpdate } = factory[$$inject] || defaultInject;
return new Component(type, token, props, shouldUpdate, displayName);
};
factory.displayName = displayName;
return factory;
}
const defaultInject = {};
const detectIsComponent = x => x instanceof Component;
const getComponentKey = x => x.props[KEY_ATTR] ?? null;
const hasComponentFlag = (inst, flag) => Boolean(inst.props[flag]);
export { Component, component, $$inject, detectIsComponent, getComponentKey, hasComponentFlag };
//# sourceMappingURL=component.js.map