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: add defineAsyncComponent API #644

Merged
merged 10 commits into from Feb 18, 2021
Merged

feat: add defineAsyncComponent API #644

merged 10 commits into from Feb 18, 2021

Conversation

mathe42
Copy link
Contributor

@mathe42 mathe42 commented Feb 10, 2021

This PR adds a implementation for defineAsyncComponent (I used code from the vue3 implementation) and returns a function async component as used in vue2 (see docs link). This should be a quite similar implementation as vue3 uses and should be compatible in most cases.

Some notes:

  1. Tests are a copy of the vue3 tests an then modified.
  2. Not shure of the typing of Component used VueProxy<any,any> but maybe there are better options
  3. Changed option suspensible as vue2 has no suspense component
  4. Helpfull docs:

const component = load()

return {
component: component as any, // there is a type missmatch between vue2 type and the docs
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Types of Vue2 are not correct in that place I created a PR for that vuejs/vue#11906

Copy link
Member

@antfu antfu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add some runtime tests as well? Thanks.

@mathe42
Copy link
Contributor Author

mathe42 commented Feb 12, 2021

Will work in it.

Should be easy with the test from vue3 https://github.com/vuejs/vue-next/blob/master/packages/runtime-core/__tests__/apiAsyncComponent.spec.ts ...

@mathe42
Copy link
Contributor Author

mathe42 commented Feb 13, 2021

Added tests.

Following things are not like vue3:

  1. On timeout a Error is displayed.
  2. Error component access to thrown Error is not the same.
  3. Resolve after timeout doesn't show the component.

@mathe42 mathe42 requested a review from antfu February 13, 2021 15:01
@antfu antfu changed the title add defineAsyncComponent API feat: add defineAsyncComponent API Feb 18, 2021
@antfu antfu merged commit 8409f48 into vuejs:master Feb 18, 2021
@mathe42
Copy link
Contributor Author

mathe42 commented Feb 18, 2021

Thanks👍

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.

None yet

2 participants