0.1.4 • Published 3 months ago

omi-suspense v0.1.4

Weekly downloads
-
License
-
Repository
github
Last release
3 months ago

omi-suspense

Handling asynchronous dependencies.

Install

npm i omi-suspense

Usage

<o-suspense
  imports={[
    import('./components/user-info'),
    import('./components/user-profile'),
  ]}
  data={async () => {
    return await fetchUserProfile(router?.params.id as string)
  }}
  onLoaded={(event: CustomEvent) => {
    userProfile.value = event.detail[2]
  }}
>
  <div slot="pending">Loading user profile...</div>
  <div slot="fallback">Sorry, we are unable to load the user profile at the moment. Please try again later.</div>
  <user-info>
    <user-profile></user-profile>
  </user-info>
</o-suspense>

Custom Render Functions

<o-suspense
  imports={[
    import('./components/user-info'),
    import('./components/user-profile'),
  ]}
  data={async () => {
    return await fetchUserProfile(router?.params.id as string)
  }}
  onLoaded={(event: CustomEvent) => {
    userProfile.value = event.detail[2]
  }}
  beforePending={async (suspense: Component) => {
    // do something such as: fade out the root el of custom render
    return new Promise((resolve) => setTimeout(resolve, 300))
  }}
  pending={<div>Loading user profile...</div>}
  customRender={(results)=> {
    return (
      <user-info>
        <user-profile></user-profile>
      </user-info>
    )
  }}
  fallback={() => {
    return <div>Sorry, we are unable to load the user profile at the moment. Please try again later.</div>
  }}
>
</o-suspense>

License

MIT © OMI

0.1.4

3 months ago

0.1.3

3 months ago

0.1.0

4 months ago

0.1.2

4 months ago

0.1.1

4 months ago

0.0.5

6 months ago

0.0.4

7 months ago

0.0.3

7 months ago

0.0.2

7 months ago

0.0.1

7 months ago