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-streams

v1.0.0-beta.5

Published

Streams for Vue

Downloads

18

Readme

⛲️ vue-streams ⛲️

A simplified approach to using streams with Vue.

Install

npm i vue-streams rxjs@rc

rxjs v6 is recommended (currently in Release Candidate)

Setup

Install as a plugin:

import VueStreams from "vue-streams"
import { Subject, BehaviorSubject } from "rxjs"
Vue.use(VueStreams, { Subject, BehaviorSubject })

Usage

Simple Example

Simple Example

<template>
  <div>
    <button @click="click$">Click me</button>
    {{random$}}
  </div>
</template>
<script>
import { fromMethod } from "vue-streams";
import { map } from "rxjs/operators";

export default {
  sources: {
    click$: fromMethod //infer the method name "click$" from the key
  },
  subscriptions: ({ click$ }) => ({
    random$: click$.pipe(map(() => Math.random()))
  }) //template subscribes to each key of the returned object
};
</script>

Standard Example

Standard Example

<template>
  <div id="demo">
    <label>Search <input type="text" v-model="term"></label>
    <button @click="term = ''">Clear</button>
    <h2 v-if="noResults$">
      {{message$}}
    </h2>
    <transition-group tag="div" name="fade" class="people">
      <div v-for="person of people$" :key="person.id">
        <h2>{{person.name}}</h2>
        <img :src="`${URL}/${person.image}`" alt="">
      </div>

    </transition-group>

  </div>
</template>
<script>
import { fromWatch } from "vue-streams"
import { merge } from "rxjs"
import {
  switchMap,
  map,
  mapTo,
  pluck,
  partition,
  debounceTime,
  share
} from "rxjs/operators"
import { ajax } from "rxjs/ajax"

const URL = `https://foamy-closet.glitch.me`

export default {
  data() {
    return { URL, term: "sky" }
  },
  sources: {
    term$: fromWatch("term")
  },
  subscriptions: ({ term$ }) => {
    const [search$, empty$] = term$.pipe(
      debounceTime(250),
      partition(term => term.length)
    )

    const people$ = merge(
      search$.pipe(
        switchMap(term =>
          ajax(`${URL}/people?name_like=${term}`).pipe(
            share(),
            pluck("response")
          )
        )
      ),
      empty$.pipe(map(() => []))
    )

    const noResults$ = people$.pipe(map(result => result.length === 0))
    const message$ = merge(
      noResults$.pipe(mapTo("No results 😢")),
      empty$.pipe(mapTo("Please type something 👍"))
    )

    return { people$, noResults$, message$ }
  }
}
</script>
<style>
#demo {
  font-family: "Avenir";
}
.people {
  display: flex;
  flex-wrap: wrap;
}

.people > * {
  padding: 0.25rem;
}
.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.5s;
}
.fade-enter,
.fade-leave-to {
  opacity: 0;
}
</style>

Crazy Example

Crazy Example

<template>
  <div id="demo" @mousemove="x = $event.x">
    <h3>{{x$}}</h3>
    <button @click="one$">One</button>
    <button @click="two">Two</button>
    <button @click="load$">Load Random</button>
    <input type="text" v-model="text">
    <button v-on:click="show = !show">
      Toggle
    </button>
    <transition name="fade" @enter="enter$">
      <p v-if="show">hello</p>
    </transition>
    <h2>
      {{message$}}
    </h2>
    <MiniComp v-if="show"></MiniComp>
  </div>
</template>
<script>
import { merge, interval } from "rxjs"
import { ajax } from "rxjs/ajax"
import { map, mapTo, switchMap, pluck, throttleTime } from "rxjs/operators"
import { fromMethod, fromWatch, fromEmit } from "vue-streams"

const MiniComp = {
  sources: {
    mounted$: fromEmit("hook:mounted"),
    beforeDestroy$: fromEmit("hook:beforeDestroy")
  },
  subscriptions: ({ mounted$, beforeDestroy$ }) => {
    mounted$.subscribe(value => console.log("hello!"))
    beforeDestroy$.subscribe(value => console.log("BYE! 🤪"))
  },
  render(h) {
    return (
      <div>
        <h2>MiniComp</h2>
      </div>
    )
  }
}

export default {
  components: {
    MiniComp
  },
  data() {
    return {
      show: false,
      text: "john"
    }
  },
  sources: {
    one$: fromMethod,
    two$: fromMethod("two"),
    load$: fromMethod,
    enter$: fromMethod,
    text$: fromWatch("text"),
    x: fromWatch
  },

  subscriptions: ({ one$, two$, load$, enter$, text$, x }) => {
    const buttons$ = merge(
      one$.pipe(mapTo(1)),
      two$.pipe(mapTo(2)),
      enter$.pipe(mapTo("fade in..."))
    )
    const date$ = interval(4000).pipe(map(() => new Date().toString()))
    const person$ = load$.pipe(
      switchMap(() =>
        ajax(
          `https://foamy-closet.glitch.me/people/${Math.floor(
            Math.random() * 10
          )}`
        ).pipe(pluck("response", "name"))
      )
    )

    const message$ = merge(person$, text$, date$, buttons$)

    return {
      message$,
      x$: x.pipe(throttleTime(100))
    }
  }
}
</script>
<style>
#demo {
  font-family: "Avenir";
}
.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.5s;
}
.fade-enter,
.fade-leave-to {
  opacity: 0;
}
</style>