JSPM

vuex2vuex

0.1.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q14593F
  • License ISC

Sync different vuex stores on clients and servers

Package Exports

  • vuex2vuex

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (vuex2vuex) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

vuex2vuex sync util

Sync different vuex stores by streaming commits. Designed to use end-to-end with websockets.

Use an authoritative store on the server for an initial sync.

For an example app see: https://github.com/Ineluki/vuexsync-example

Basic usage

const stream = new Sync.TransportStream(websocket);
const plugin = Sync.Plugin( stream, {} );
const store = Store([plugin]);

API

Sync.TransportStream

A duplex stream for connecting to a websocket. Has a buffer for events that get pushed before the socket is open.

Sync.Plugin

Creates a duplex stream as a vuex plugin. Will listen to any commits and pushes them over the stream. Will take any incoming packets and commit them. Can employ a filter to only listen to certain commits.

Options

Options are given as the second argument.

  • initSync - request a full synchronisation of the store on start. Requires a Hub somewhere up the stream with an authoritative store set
  • filter - object, to limit the commit names listened to
  • whitelist - array or names to listen to
  • blacklist - array of names not to listen to
  • namespace - string, only listen to commits in that namespace, can be used with other filters

Sync.Hub

A pseudo stream that can connect multiple streams, useful for rooms of websockets. Not a real stream but you can pipe to and from it. The hub will do the unpiping for you when one stream closes.

Usage:

const stream = new Sync.TransportStream(ctx.websocket);
stream.pipe(hub).pipe(stream);