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-syncers-feathers

v0.4.1

Published

Synchronises feathers services with vue objects, updated in real time

Downloads

49

Readme

vue-syncers-feathers

Synchronises feathers services with vue objects, updated in real-time

Build Status Coverage Status Scrutinizer Code Quality

Changelog on GitHub releases

Setup

npm install vue-syncers-feathers feathers-commons feathers-query-filters --save

Webpack/Browserify

// Set up feathers client
// You can do this whatever way you prefer, eg. feathers-client
import feathers from 'feathers/client'
import feathersIO from 'feathers-socketio/client'
import io from 'socket.io-client'
const socket = io()
const client = feathers().configure(feathers.socketio(socket))

// Set up vue & VueSyncersFeathers
import Vue from 'vue'
import VueSyncersFeathers from 'vue-syncers-feathers'

Vue.use(VueSyncersFeathers, {
	feathers: client
})

Configuration

ADVANCED - Most of the time you do not need these

  • driver - Swapping out syncers with your own custom version. See src/syncer.js
  • filter - Function that parses the query for special filters. Check feathers-query-filters for syntax.
  • matcher - Function that creates a matcher used to check if an item matches the query. By default feathers-commons matcher is used.

Usage

<template>
	<div class="user-list">
		<div v-for="user in userList">
			{{user | json}}
		</div>
	</div>
</template>
<script>
export default {
	sync: {
		// put all results in users service on userList
		userList: 'users',
		// put a user with id 1 on userObject
		userObject: {
			service: 'users',
			id() {
				return 1
			}
		},
		// put filtered users list on specialUsers
		specialUsers: {
			service: 'users',
			query() {
				return {
					// All users where user.special === true
					special: true
				}
			}
		}
	}
}
</script>

sync option object

key: path where the object will be (vm.key)
value: string|object Service to use, or options object:

General syncer settings

  • service: string service to use (same as feathers.service(value))
  • idField: string ID field (defaults to id)
  • loaded: function() that will be executed when the syncer is loaded. This can happen multiple times (if data is loaded again).
  • errored: function(error) that will be executed when the syncer loads an error. This can happen multiple times (if data is loaded again).

To use loaded and error event handler on all syncers check instance events

Collection options (default)

  • query: function()|string query to send to the server

vm.key will be object where keys are object IDs (empty if none matches/all deleted)

Single item options (if id is set)

  • id: function()|string function that returns the item ID to fetch.

vm.key will be the object which ID matches (or null on error/deletion)

Reactivity

Both id and query are sent to vm.$watch to get and observe the value. If the value is changed (eg. id: () => { return this.shownUserId } and this.shownUserId = 3 later), the new object is requested from the server. If new the value is null, the request won't be sent and current value is set to empty object (collection mode) or null (single item mode)

export default {
	data() {
		return {
			userId: 1
		}
	},
	sync: {
		user: {
			service: 'users',
			id() {
				return this.userId
			}
		}
	}
}

instance.userId = 2 // loads user id = 2

Instance methods

  • vm.$refreshSyncers([path]) - Refresh syncers on this instance. Path can be key or array of keys to refresh. If not set, all syncers are updated. Note that this does not need to be called after creating/updating/removing items unless events have been disabled.

Instance properties

  • vm.$feathers - Feathers client
  • vm.$loadingSyncers (reactive) - true if any syncers are in loading state

Instance events

  • syncer-loaded(key) - Emitted when one of the syncers finishes loading it's data
  • syncer-error(key, error) - Emitted when one of the syncers results in error while loading it's data

Aliases

For cleaner code you can enable the following aliases by setting aliases option true in the Vue.use call. Note that these aren't enabled by default to avoid conflicts with any other vue plugins you might be using.

Alias | Is same as | Key for individual enabling ---|---|--- vm.$loading | vm.$loadingSyncers | loading vm.$refresh() | vm.$refreshSyncers | refresh vm.$service(name) | vm.$feathers.service(name) | service

// Enable all
Vue.use(VueSyncersFeathers, {
	aliases: true,
	feathers: client
})
// Enable some
Vue.use(VueSyncersFeathers, {
	aliases: {
		loading: true,
		service: true
	},
	feathers: client
})

Example component with aliases:

<template>
	<div>
		<div v-if="$loading">Loading...</div>
		[...]
	</div>
</template>
<script>
export default {
	methods: {
		addNewUser(user) {
			this.$service('users').create(user).then(() => {
				//...
			})
		}
	},
	sync: {
		users: 'users',
	}
}
</script>

FAQ

  • Can I use computed variables in query/id
    Yes
  • Can I use results in computed variables
    Yes
  • Vue-router/other plugin's objec--
    Untested, but probably anything that integrates with vue (and properly defines reactivity) works

Compatibility warnings:

  • feathers-socket-commons 2.2.0 - 2.3.0: Broken event listener removal