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

@tygr/vue-async-filter

v1.1.3

Published

A simple mixin that adds the async filter to vue

Downloads

149

Readme

Vue Async Filter

Build Status

This mixin allows you to use promises and observables in your vue templates. This is meant to emulate angular's async pipe.

DEMO

Installation

yarn add -D @tygr/vue-async-filter

Or

npm install --save-dev @tygr/vue-async-filter

It's recommended that you include it on a per-component basis:

import { AsyncFilterMixin } from '@tygr/vue-async-filter'

export default {
  mixins: [AsyncFilterMixin]
}

You may also register the mixin globally:

import Vue from 'vue'

import { AsyncFilterMixin } from '@tygr/vue-async-filter'


Vue.mixin(AsyncFilterMixin)

Usage

The async filter requires a unique 'key' parameter

  • keys are scoped to the component
  • This is to prevent duplication on rerender, since all filters are re-evaluated each time the component renders

The async filter returns null while waiting for the first value. You can use the || operator to pass in a fallback value

Filters can only be used in mustache syntax currently. If you wish to use asynchronous data in a directive, use the $async function

  • First parameter is the asynchronous datum, the second parameter is the key

All observables are unsubscribed from in the beforeDestroy hook of the vue component they are used in.

<template>
  <div>
    <h1>{{ interval | async('interval') }}</h1>
    <h1>{{ getTimeoutPromise('Promise has resolved') | async('timeout-promise') || 'loading...' }}</h1>
    <h1 v-for="factor in $async(factors, 'factors')">
      {{ getIntervalWithFactor(factor) | async('interval-factor-' + factor) }}
    </h1>
  </div>
</template>
import { interval } from 'rxjs'
import { map } from 'rxjs/operators'

import { AsyncFilterMixin } from '@tygr/vue-async-filter'

export default {
  mixins: [AsyncFilterMixin],
  data: () => ({
    interval: interval(1000),
    factors: new Promise(resolve => setTimeout(
      () => resolve([6, 7, 8, 9]),
      2000
    ))
  }),
  methods: {
    getIntervalWithFactor(factor) {
      return this.interval.pipe(
        map(val => factor * val)
      )
    },
    getTimeoutPromise(msg) {
      return new Promise(resolve => {
        setTimeout(
          () => resolve(msg),
          2000
        )
      })
    }
  }
}

Benefits over vue-rx

  • Support for promises
  • Runtime creation of observables
    • vue-rx forces you to declare all observables at compile time. With the async filter, you can use functions that return an observable or promise. This is useful in v-for loops.
  • Smaller build (based on webpack-bundle-analyzer)
    • vue-rx: 3.06 KB gzipped
    • @tygr/vue-async-filter: 511 B gzipped

Detriments

  • No vue-dev-tools support (yet)

Development

yarn build

The 'vue' package in the root node_modules cannot be linked to the test project, so instead you must install the tarball that is created by yarn build manually:

cd test
yarn remove @tygr/vue-async-filter
yarn cache clean
yarn add -D ../vue-async-filter.tgz