All Projects → t2t2 → vue-syncers-feathers

t2t2 / vue-syncers-feathers

Licence: MIT License
Synchronises feathers services with vue objects, updated in real time

Programming Languages

javascript
184084 projects - #8 most used programming language
Vue
7211 projects
HTML
75241 projects

Projects that are alternatives of or similar to vue-syncers-feathers

feathers-objection
Feathers database adapter for Objection.js, an ORM based on KnexJS SQL query builder for Postgres, Redshift, MSSQL, MySQL, MariaDB, SQLite3, and Oracle. Forked from feathers-knex.
Stars: ✭ 89 (+169.7%)
Mutual labels:  feathersjs
moleculer-adapter-feathers
Moleculer service mixin wrapping Feathers.js services
Stars: ✭ 17 (-48.48%)
Mutual labels:  feathersjs
serum-price-api
An easy to use API to know SPL Tokens price.
Stars: ✭ 23 (-30.3%)
Mutual labels:  feathersjs
Feathers
A framework for real-time applications and REST APIs with JavaScript and TypeScript
Stars: ✭ 13,761 (+41600%)
Mutual labels:  feathersjs
krawler
A minimalist (geospatial) ETL
Stars: ✭ 51 (+54.55%)
Mutual labels:  feathersjs
redux-crud-example
Basic crud react-redux-featherjs app for managing contacts
Stars: ✭ 54 (+63.64%)
Mutual labels:  feathersjs
react-native-mobx-feathers
A basic App using react-navigation + mobx + feathers
Stars: ✭ 31 (-6.06%)
Mutual labels:  feathersjs
feathers-shallow-populate
Feathersjs populate relational data
Stars: ✭ 21 (-36.36%)
Mutual labels:  feathersjs
flutter feathersjs.dart
Communicate with your feathers js server from flutter app with unbelieved ease and make happy your customers.
Stars: ✭ 19 (-42.42%)
Mutual labels:  feathersjs
quasar-starter-ssr-pwa-jest-cypress
Accelerated starter kit for building a quasar 17 app.
Stars: ✭ 49 (+48.48%)
Mutual labels:  feathersjs
mobx-crud-example
A crud mobx project using react, featherjs and mongodb
Stars: ✭ 22 (-33.33%)
Mutual labels:  feathersjs
feathers-blob
Feathers service for blob storage, like S3.
Stars: ✭ 89 (+169.7%)
Mutual labels:  feathersjs
feathers-findone
Adds a .findOne() method to services in Feathers.js
Stars: ✭ 14 (-57.58%)
Mutual labels:  feathersjs
Awesome Cheatsheets
👩‍💻👨‍💻 Awesome cheatsheets for popular programming languages, frameworks and development tools. They include everything you should know in one single file.
Stars: ✭ 26,007 (+78709.09%)
Mutual labels:  feathersjs
feathers-casl
feathers.js + casl: hooks & channels
Stars: ✭ 25 (-24.24%)
Mutual labels:  feathersjs
react-menu-monkey-client
Frontend for a recipe box website
Stars: ✭ 59 (+78.79%)
Mutual labels:  feathersjs
feathers-versionate
Create and work with nested services.
Stars: ✭ 29 (-12.12%)
Mutual labels:  feathersjs
FlipED
A LMS built specifically for Thailand's Education 4.0 system.
Stars: ✭ 24 (-27.27%)
Mutual labels:  feathersjs
express
[MOVED] Feathers Express framework bindings and REST transport plugin
Stars: ✭ 15 (-54.55%)
Mutual labels:  feathersjs
vue-feathers-chat
A sample realtime chat made with Vue and Feathers.
Stars: ✭ 50 (+51.52%)
Mutual labels:  feathersjs

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(feathersIO(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
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].