Sha256: e3db375a26b8a3d20a2989fa6d3a74fb1cb3eb625baa379fe88a824bf26b7674
Contents?: true
Size: 1.1 KB
Versions: 16
Compression:
Stored size: 1.1 KB
Contents
import { getData } from "@helpers/alpine"; import { nameFunction } from "@helpers/lang.js"; import { withAttrs, withOptions } from "@js/base/mixins"; function CocoComponent(name, fn) { const func = nameFunction(name, (...args) => { const data = fn(...args); Object.defineProperties(data, { $parent: { get() { return getData(this.$root.parentElement); }, }, }); data.$options = {}; if (data.use === false) return data; // TODO - remove all mixin code below once directives are ready const originalInit = data.init; const mixins = [withAttrs(), withOptions(), ...(data.use || [])]; mixins.forEach((mixin) => { if (mixin.props) { mixin.props.forEach((prop) => { if (!data[prop]) { data[prop] = null; } }); } }); return Object.assign(data, { init() { mixins.forEach((mixin) => mixin(this)); if (originalInit) { originalInit.call(this); } }, }); }); func.component = true; return func; } export { CocoComponent };
Version data entries
16 entries across 16 versions & 1 rubygems