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

feat: return root instance if not mounted #182

Merged
merged 1 commit into from
Oct 15, 2019

Conversation

pimlie
Copy link

@pimlie pimlie commented Oct 15, 2019

This pr supports delayed mounting of the Vue app by returning the root Vue instance in getVueInstance if no children exists yet

This makes the following possible:

let customElementRoot
...
  beforeCreateVueInstance(root) {
    customElementRoot = root.el
    delete root.el
    return root
  },
  vueInstanceCreatedCallback() {
    const app = this.getVueInstance()
    // do some stuff with the vue instance
    app.$mount(customElementRoot)
  }

@karol-f
Copy link
Owner

karol-f commented Oct 15, 2019

Can You please elaborate what is the use case of this PR. What problem it solves?

Avoiding errors when there's delayed mounting?

Is there use case that can be maybe solved other way?

@pimlie
Copy link
Author

pimlie commented Oct 15, 2019

I've created a module/wrapper to use a Nuxt SPA as a custom element. Although it seems to work fine already, Nuxt does some extra initialization between creating the Vue instance and mounting the instance. To prevent any differences in behaviour I'd like to stay as close as possible to the default Nuxt implementation, hence this pr.

@karol-f karol-f merged commit ce2f2b7 into karol-f:master Oct 15, 2019
@karol-f
Copy link
Owner

karol-f commented Oct 15, 2019

Merged and released in https://github.com/karol-f/vue-custom-element/releases/tag/v3.2.10

@pimlie
Copy link
Author

pimlie commented Oct 15, 2019

Damn you are fast, it must be a new Github record from pr to review to release! Many thanks ;)

@pimlie pimlie deleted the feat-support-delayed-mounting branch October 15, 2019 09:11
@pimlie
Copy link
Author

pimlie commented Oct 15, 2019

Hmm, could you please verify if the npm publish was succesfull? It could also be that the npm cache is bogging again, but the 3.2.10 release is not yet listed: https://www.npmjs.com/package/vue-custom-element

@karol-f
Copy link
Owner

karol-f commented Oct 15, 2019

Checking...

@karol-f
Copy link
Owner

karol-f commented Oct 15, 2019

Done, sorry for the inconvenience.

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

Successfully merging this pull request may close these issues.

2 participants