karol-f / vue-custom-element

Vue Custom Element - Web Components' Custom Elements for Vue.js
https://karol-f.github.io/vue-custom-element/
MIT License
1.97k stars 187 forks source link

beforeCreateVueInstance can now return a promise #243

Closed rob-64 closed 3 years ago

rob-64 commented 3 years ago

Allows developer to perform any async calls to init the root vue opts

rob-64 commented 3 years ago

@karol-f any chance of reviewing this?

karol-f commented 3 years ago

Can You please describe what You want to achieve? What problem does this solution solve?

rob-64 commented 3 years ago

Can You please describe what You want to achieve? What problem does this solution solve?

I have a very unique use case where I need to fetch some instanced props and initial vuexState during Vue init... so by returning a promise, I can use an ajax call to get what I need from the server

karol-f commented 3 years ago

Ok, so why not making a beforeCreateVueInstance a Promise? Will it work? Seems a little bit cleaner.

rob-64 commented 3 years ago

Ok, so why not making a beforeCreateVueInstance a Promise? Will it work?

Thats what I did... it can now return the Options or a Promise

@karol-f or maybe I misunderstand what you're saying

karol-f commented 3 years ago

Hi, checking Your PR, I can see that You are modifying createVueInstance and not beforeCreateVueInstance - that's why I'm asking.

I didn't analyse if solution You've introduced is better one. I'm still not sure if it's necessary. At least in that form. screenshot_346 screenshot_347

rob-64 commented 3 years ago

Hi, checking Your PR, I can see that You are modifying createVueInstance and not beforeCreateVueInstance - that's why I'm asking.

I didn't analyse if solution You've introduced is better one. I'm still not sure if it's necessary. At least in that form. screenshot_346 screenshot_347

Gotcha, so I made it so that the function beforeCreateVueInstance can return either the options or a promise of the options.

So then inside the util function of createVueInstance I chain off of the promise and return true once the options are returned and then the vue instance is created. That way I only invoke the vueInstanceCreatedCallback once its truly done.

image

image

rob-64 commented 3 years ago

@karol-f does that make sense what my plan was? I still don't understand what you are suggesting.

karol-f commented 3 years ago

Hi, I am currently a little busy, I will try to get back to it as soon as possible.

rob-64 commented 3 years ago

Hi, I am currently a little busy, I will try to get back to it as soon as possible.

Hi @karol-f, any chance we could continue this PR?

rob-64 commented 3 years ago

@karol-f Can we review this PR again?

I updated createVueInstance to return a Promise so I can chain it with the Promise now returned by beforeCreateVueInstance....

karol-f commented 3 years ago

Hi, thank You for the PR. Sorry for the long wait. It looks good!

karol-f commented 3 years ago

I've copied Your changes (not merging the branch) as some changes (like dist or docs updating) I do during release. I hope it's ok with You.