0.2.4 • Published 5 years ago

@wranggle/storage-remote v0.2.4

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
5 years ago

Remote Store

This package contains two classes:

  • RemoteRelayAdapter is a persistence adapter, letting you use WranggleStorage in a window/process different from the one actually storing your data. It behaves like normal, transparently sending data requests over @wranggle/rpc to a different window/process, the one that has the actual store.

  • RpcStorageListener listens for and serves requests sent by another window/process.

RemoteRelayAdapter

RemoteRelayAdapter is a WranggleStorage persistence adapter. It is not bundled in the @wranggle/storage-node or @wranggle/storage-web packages, but otherwise behaves like any other store.

You can create it using the remote shortcut:

import { RemoteRelayAdapter } from '@wranggle/storage-remote';
const rpcOpts = {
  channel: 'main-data',
  transport: 'chrome'
}
const store = new WranggleStorage({ remote:  rpcOpts });    

The other window/process must set its corresponding rpcOpts (eg, channel and transport) such that they can communicate over @wranggle/rpc.

RpcStorageListener

RpcStorageListener sets up a @wranggle/rpc request handler to respond to data method requests sent by a RemoteRelayAdapter in a different window/process.

You create it with an existing WranggleStorage instance, plus rpcOpts that can communicate with the other window/process. Eg:

import { RpcStorageListener } from '@wranggle/storage-remote';
const listener = new RpcStorageListener(someExistingStore, {
  channel: 'main-data',
  transport: 'chrome'            
});

Methods

  • stopTransport