UNPKG

@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)

47 lines (46 loc) 1.53 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); exports.hasComponentFlag = exports.getComponentKey = exports.detectIsComponent = exports.$$inject = exports.component = exports.Component = void 0; const constants_1 = require('../constants'); const $$inject = Symbol('inject'); exports.$$inject = $$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); } } exports.Component = Component; 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; } exports.component = component; const defaultInject = {}; const detectIsComponent = x => x instanceof Component; exports.detectIsComponent = detectIsComponent; const getComponentKey = x => x.props[constants_1.KEY_ATTR] ?? null; exports.getComponentKey = getComponentKey; const hasComponentFlag = (inst, flag) => Boolean(inst.props[flag]); exports.hasComponentFlag = hasComponentFlag; //# sourceMappingURL=component.js.map