Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: loop and iterate entry tags #522

Merged

Conversation

zackspear
Copy link

  • What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)

Fix for #521

  • What is the new behavior (if this is a feature change)?

Multiple entry tags should now work

@zackspear zackspear mentioned this pull request May 22, 2023
21 tasks
@ThornWalli
Copy link
Contributor

ThornWalli commented May 23, 2023

@zackspear Was my first thought too 🙃

Unfortunately we have to note one thing, the import between async and not async is different.

Therefore there was an extra counter (i) in the loop for not async.
Because only the not async has a fixed import with variable.

Do you want to adjust this again?

<% let i = 0; %><%= options.tags.map(function ({ async, name, path }) {
  let tag;
  if (async) {
    tag = `    ['${name}', defineAsyncComponent(() => { return import('${path}').then(module => (typeof module.default === 'function' ? (new module.default).$options : module.default) ); })]`;
  } else {
    tag = `    ['${name}', (typeof Component${i} === 'function' ? (new Component${i}).$options : Component${i})]`;
    i++;
  }
  return tag;
 }).join(',\n') %>

image

The i++ must come before the return 🙂

@zackspear
Copy link
Author

zackspear commented May 23, 2023

@ThornWalli ah ok. Maybe you're wanting something like this? If so I can make another commit with this in the PR 😄

This seems to work in my local test environment.

import { defineAsyncComponent, defineCustomElement } from 'vue'

<%= options.tags.filter(function ({ async }) { return !async; }).map(({ path }, i) => `import Component${i} from '${path}';`).join('\n') %>

const defineTags = () => {
  const elements = [
<% let i = 0; %><%= options.tags.map(function ({ async, name, path }) {
  let tag;
  if (async) {
    tag = `    ['${name}', defineAsyncComponent(() => { return import('${path}').then(module => (typeof module.default === 'function' ? (new module.default).$options : module.default) ); })]`;
  } else {
    tag = `    ['${name}', (typeof Component${i} === 'function' ? (new Component${i}).$options : Component${i})]`;
  }
  i++;
  return tag;
 }).join(',\n') %>
  ].forEach(([name, component]) => {
    const CustomElement = defineCustomElement(component);
    window.customElements.define(name, CustomElement);
  })
};

const setup = () => {
  defineTags();
};

setup();

@ThornWalli
Copy link
Contributor

The i++ must be in the else :)

You can set the first component to async: true for example.

When the PR is adjusted, I merge it in.

import { defineAsyncComponent, defineCustomElement } from 'vue'

<%= options.tags.filter(function ({ async }) { return !async; }).map(({ path }, i) => `import Component${i} from '${path}';`).join('\n') %>

const defineTags = () => {
  const elements = [
<% let i = 0; %><%= options.tags.map(function ({ async, name, path }) {
  let tag;
  if (async) {
    tag = `    ['${name}', defineAsyncComponent(() => { return import('${path}').then(module => (typeof module.default === 'function' ? (new module.default).$options : module.default) ); })]`;
  } else {
    tag = `    ['${name}', (typeof Component${i} === 'function' ? (new Component${i}).$options : Component${i})]`;
    i++;
  }
  return tag;
 }).join(',\n') %>
  ].forEach(([name, component]) => {
    const CustomElement = defineCustomElement(component);
    window.customElements.define(name, CustomElement);
  })
};

const setup = () => {
  defineTags();
};

setup();

@ThornWalli ThornWalli merged commit 3983222 into GrabarzUndPartner:beta May 24, 2023
1 of 2 checks passed
@github-actions
Copy link

🎉 This PR is included in version 2.0.0-beta.13 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants