Sha256: bf778e98646e482ddba043f29dbf852d16ad683f0ec4d8f4ee78671295198613

Contents?: true

Size: 781 Bytes

Versions: 73

Compression:

Stored size: 781 Bytes

Contents

function registerComponents(components) {
  document.addEventListener("alpine:init", () => {
    components.forEach((module) => {
      if (module.default && module.default.component === true) {
        Alpine.data(module.default.name, module.default);
      }
    });
  });
  return components;
}

function getComponent(el, throwOnError = false) {
  try {
    return Alpine.$data(el);
  } catch (error) {
    if (throwOnError) {
      throw error;
    } else {
      return null;
    }
  }
}

function getData(el) {
  const root = Alpine.closestRoot(el);
  return root ? Alpine.$data(root) : null;
}

function setData(el, newData) {
  const data = getData(el);
  return data ? Object.assign(data, newData) : null;
}

export { registerComponents, getComponent, getData, setData };

Version data entries

73 entries across 73 versions & 1 rubygems

Version Path
coveragebook_components-0.19.8 app/assets/js/helpers/alpine.js
coveragebook_components-0.19.7 app/assets/js/helpers/alpine.js
coveragebook_components-0.19.6 app/assets/js/helpers/alpine.js
coveragebook_components-0.19.5 app/assets/js/helpers/alpine.js
coveragebook_components-0.19.4 app/assets/js/helpers/alpine.js
coveragebook_components-0.19.3 app/assets/js/helpers/alpine.js
coveragebook_components-0.19.2 app/assets/js/helpers/alpine.js
coveragebook_components-0.19.1 app/assets/js/helpers/alpine.js
coveragebook_components-0.19.0 app/assets/js/helpers/alpine.js
coveragebook_components-0.18.8 app/assets/js/helpers/alpine.js
coveragebook_components-0.18.7 app/assets/js/helpers/alpine.js
coveragebook_components-0.18.0 app/assets/js/helpers/alpine.js
coveragebook_components-0.17.7 app/assets/js/helpers/alpine.js
coveragebook_components-0.17.6 app/assets/js/helpers/alpine.js
coveragebook_components-0.17.5 app/assets/js/helpers/alpine.js
coveragebook_components-0.17.4 app/assets/js/helpers/alpine.js
coveragebook_components-0.17.3 app/assets/js/helpers/alpine.js
coveragebook_components-0.17.2 app/assets/js/helpers/alpine.js
coveragebook_components-0.17.1 app/assets/js/helpers/alpine.js
coveragebook_components-0.17.0 app/assets/js/helpers/alpine.js