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-feathers/vue-feathers

v0.5.1

Published

Vue components and helper functions for Feathers

Downloads

90

Readme

vue-feathers

Feathers helpers and components for Vue

Getting Started

npm install @vue-feathers/vue-feathers

You'll need to set up a feathers client in your app. Each client is different. This example client uses SocketIO and feathers-reactive for real-time events.

import feathers from '@feathersjs/feathers'
import socketio from '@feathersjs/socketio-client'
import reactive from 'feathers-reactive'
import io from 'socket.io-client'

const socket = io('http://localhost:3030', {transports: ['websocket']})

export const feathersClient = feathers()
  .configure(socketio(socket))
  .configure(reactive({idField:'_id'}))

Then import and install the vue-feathers plugin

import Vue from 'vue'
import feathersClient from 'path/to/your/feathers/client'
import VueFeathers from '@vue-feathers/vue-feathers'

Vue.use(VueFeathers, { feathersClient })

Nuxt

Just put the above code in a js file and register it in nuxt.config.js as a plugin.

The Feathers Client: $F

The plugin registers the feathers client on all Vue components under this.$F, so in a component you could fetch and display all users like so:

export default {
  data() {
    return {
      users: [], // Initialize for storing fetched users 
    }
  },
  mounted() {
    this.findUsers()
  },
  methods: {
    findUsers() {
      this.$F.service('users')
        .find()               // Find all users.
        .then(users => {      // When the data arrives... 
          this.users = users  // store it.
        })
    }
  }
}

Mixins

The above scenario is so common that I wrapped it in a mixin. Using the same example with the same HTML:

import { mixins } from '@vue-feathers/vue-feathers'
const usersMixin = mixins.ListsMixin(['users']) // takes a list of service names

export default {
  mixins: [usersMixin], // handles the data hookup and provides some useful methods
  mounted() {
    this.find('users') // or use this.findAll() to fetch all at once
  },
}

This approach scales nicely:

const mixin = mixins.ListsMixin(['users', 'groups', 'roles', 'permissions', 'profiles'])

export default {
  mixins: [mixin],
  mounted() {
    this.findAll()
  },
}

Real-Time Data

feathers-reactive provides data stream interfaces that we can tap into. Assuming your feathers client has feathers-reactive installed, you can make a reactive list for the users example above like so:

export default {
  data() {
    return {
      users: [], // Initialize for storing fetched users
      subscription: null, // Initialize for storing the subscription to the 'users' endpoint 
    }
  },
  mounted() {
    this.sub()
  },
  methods: {
    sub(query) {
      this.unsub() // Unsub before sub in case component is remounted (ex. hot reload in dev mode)
      this.subscription = this.$F.service('users')
        .watch() // Watch 'users' for changes.
        .find({ query })  // On change, fetch all records.
        .subscribe(users => { // Whenever data arrives... 
          this.users = users  // store it.
        })
    },
    unsub() {
      if (this.subscription) {
        this.subscription.unsubscribe()
        this.subscription = null
      }
    }
  }
}

And again I provide a mixin to simplify:

import {mixins} from '@vue-feathers/vue-feathers'
const usersMixin = mixins.StreamsMixin(['users'])

export default {
  mixins: [usersMixin],
  mounted() {
    this.sub('users', { /* optional query goes here */ }) 
    // or use this.subAll(query) to subscribe to all at once
  },
}

And it scales in the same manner as the ListsMixin.

Data Provider Components

Here's where the magic happens. These data providers dynamically fetch and provide data via scoped slots.

Notes:

  • they render no DOM, like <template> and <slot> elements
  • :class and such do nothing on these components

Observable Stream

Subscribes to a query on an endpoint. Use the paginated prop to indicate if the endpoint returns a paginated response.

Provides an object of the form { stream, loading, refresh, pagination }. (See Scoped Props below for details.)

<observable-stream paginated endpoint="users" :query="{ active: true }">
  <template v-slot="{ stream, loading, refresh, pagination }">
    <pre v-for="record in stream">{{ record }}</pre>    
  </template>
</observable-stream>

Scoped Props

  • stream is an array of DB records, defaulting to an empty array before data arrives
  • loading is false when requested data has been fetched, true when waiting for requested data
  • refresh is a function that resets the stream and re-fetches data
  • pagination is data is present when "paginated" is set to true on observable-stream

Observable Streams (deprecated)

Subscribes to a set of endpoint queries given an object of the form { endpoint: query, ... }.

Provides an object of the form { endpoint: stream,... }.

<observable-streams :queryset="{ users: { active: true } }">
  <template v-slot="{ users }">
    <pre>{{ users }}</pre>
  </span>
</observable-streams>

Observable Object (deprecated)

Fetches the first element of the provided query from a single endpoint.

<observable-object endpoint="users" :query="{ username: 'moot' }">
  <div v-slot="{ object }">
    {{datum}}
  </div>
</observable-object>