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

Version Path
coveragebook_components-0.7.1 app/assets/js/coco.js
coveragebook_components-0.7.0 app/assets/js/coco.js
coveragebook_components-0.6.5 app/assets/js/coco.js
coveragebook_components-0.6.4 app/assets/js/coco.js
coveragebook_components-0.6.3 app/assets/js/coco.js
coveragebook_components-0.6.2 app/assets/js/coco.js
coveragebook_components-0.6.1 app/assets/js/coco.js
coveragebook_components-0.6.0 app/assets/js/coco.js
coveragebook_components-0.5.7 app/assets/js/coco.js
coveragebook_components-0.5.6 app/assets/js/coco.js
coveragebook_components-0.5.5 app/assets/js/coco.js
coveragebook_components-0.5.4 app/assets/js/coco.js
coveragebook_components-0.5.3 app/assets/js/coco.js
coveragebook_components-0.5.2 app/assets/js/coco.js
coveragebook_components-0.5.1 app/assets/js/coco.js
coveragebook_components-0.5.0 app/assets/js/coco.js