npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vue-promised-prefixed

v1.0.2

Published

Promises as components

Downloads

4

Readme

vue-promised Build Status npm package coverage thanks

Transform your Promises into components !

Installation

npm install vue-promised
# or
yarn add vue-promised

Migrating from v0.2.x

Migrating to v1 should be doable in a small amount of time as the only breaking changes are some slots name and the way Promised component is imported. Check releases notes to see the list of breaking changes

Usage

Import the component to use it

import { Promised } from 'vue-promised'

Vue.component('Promised', Promised)

promise should be a Promise but can also be null. data will contain the result of the promise. You can of course name it the way you want:

Using pending, default and rejected slots

<Promised :promise="promise">
  <!--
    Use the "pending" slot for loading content
  -->
  <h1 slot="pending">Loading</h1>
  <!-- The default scoped slots will be used as the result -->
  <h1 slot-scope="data">Success!</h1>
  <!-- The "rejected" scoped slot will be used if there is an error -->
  <h1 slot="rejected" slot-scope="error">Error: {{ error.message }}</h1>
</Promised>

Using one single combined slot

You can also provide a single combined slot that will receive a context with all relevant information

<Promised :promise="promise">
  <pre slot="combined" slot-scope="{ isPending, isDelayOver, data, error }">
    pending: {{ isPending }}
    is delay over: {{ isDelayOver }}
    data: {{ data }}
    error: {{ error && error.message }}
  </pre>
</Promised>

This allows to create more advanced async templates like this one featuring a Search component that must be displayed while the searchResults are being fetched:

<Promised :promise="searchResults" :pending-delay="200">
  <div slot="combined" slot-scope="{ isPending, isDelayOver, data, error }">
    <!-- data contains previous data or null when starting -->
    <Search :disabled-pagination="isPending || error" :items="data || []">
      <!-- The Search handles filtering logic with pagination -->
      <template slot-scope="{ results, query }">
        <ProfileCard v-for="user in results" :user="user"/>
      </template>
      <!-- If there is an error, data is null, therefore there are no results and we can display
      the error -->
      <MySpinner v-if="isPending && isDelayOver" slot="loading"/>
      <template slot="noResults">
        <p v-if="error" class="error">Error: {{ error.message }}</p>
        <p v-else class="info">No results for "{{ query }}"</p>
      </template>
    </Search>
  </div>
</Promised>

context object

  • isPending: is true while the promise is in a pending status. Becomes true once the promise is resolved or rejected. It is resetted to false when promise prop changes.
  • isDelayOver: is true once the pendingDelay is over or if pendingDelay is 0. Becomes false after the specified delay (200 by default). It is resetted when promise prop changes.
  • data: contains last resolved value from promise. This means it will contain the previous succesfully (non cancelled) result.
  • error: contais last rejection or null if the promise was fullfiled.

API Reference

Promised component

Promised will watch its prop promise and change its state accordingly.

props

| Name | Description | Type | | -------------- | ------------------------------------------------------------------------------ | --------- | | promise | Promise to be resolved | Promise | | tag | Wrapper tag used if multiple elements are passed to a slot. Defaults to span | String | | pendingDelay | Delay in ms to wait before displaying the pending slot. Defaults to 200 | Number |

slots

| Name | Description | Scope | | ---------- | ------------------------------------------------------------------------------- | ---------------------------------------- | | pending | Content to display while the promise is pending and before pendingDelay is over | — | | default | Content to display once the promise has been successfully resolved | data: resolved value | | rejected | Content to display if the promise is rejected | error: rejection reason | | combined | Combines all slots to provide a granular control over what should be displayed | context See details |

License

MIT