UNPKG

@surface/custom-element

Version:

Provides support of directives and data binding on custom elements.

26 lines (25 loc) 1.06 kB
export const STATIC_METADATA = Symbol("custom-element:static-metadata"); export default class StaticMetadata { constructor() { this.converters = {}; this.shadowRootInit = { mode: "open" }; this.observedAttributes = []; this.styles = []; } static from(target) { if (!Reflect.has(target, STATIC_METADATA)) { Reflect.defineProperty(target, STATIC_METADATA, { configurable: false, enumerable: false, value: new StaticMetadata() }); } else if (!target.hasOwnProperty(STATIC_METADATA)) { Reflect.defineProperty(target, STATIC_METADATA, { configurable: false, enumerable: false, value: Reflect.get(target, STATIC_METADATA).inherit() }); } return Reflect.get(target, STATIC_METADATA); } inherit() { const clone = new StaticMetadata(); clone.converters = { ...this.converters }; clone.observedAttributes = [...this.observedAttributes]; clone.styles = [...this.styles]; return clone; } }