@aurox/distributed-observables
Advanced tools
Comparing version 0.0.3 to 0.0.4
@@ -16,3 +16,4 @@ import { Patch } from 'immer'; | ||
private _channel; | ||
constructor(channel: ChannelClient, options: ObservableManagerOptions); | ||
constructor(options: ObservableManagerOptions); | ||
setChannelClient(channel: ChannelClient): void; | ||
getObserver<T extends ObservableState>(topic: string, options?: Partial<ObservableOptions>): Observable<any>; | ||
@@ -19,0 +20,0 @@ private requestSnapshot; |
@@ -7,5 +7,8 @@ "use strict"; | ||
class ObservableManager { | ||
constructor(channel, options) { | ||
constructor(options) { | ||
this._observers = new Map(); | ||
this._channel = null; | ||
this._options = options; | ||
} | ||
setChannelClient(channel) { | ||
this._channel = channel; | ||
@@ -37,5 +40,11 @@ } | ||
async requestSnapshot(id) { | ||
if (!this._channel) { | ||
throw new Error('Channel Client is not set on Observable Manager'); | ||
} | ||
return this._channel.requestSnapshot({ id }); | ||
} | ||
async applyPatch(id, patches, revision) { | ||
if (!this._channel) { | ||
throw new Error('Channel Client is not set on Observable Manager'); | ||
} | ||
return this._channel.applyPatch({ id, patches, revision }); | ||
@@ -42,0 +51,0 @@ } |
{ | ||
"name": "@aurox/distributed-observables", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "A set of isomorphic helpers to enable distributed object sharing using the observer pattern", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -11,4 +11,6 @@ import { enablePatches } from 'immer'; | ||
const manager = new ObservableManager(channel, { defaultPersistDebounceTimeout: 100, defaultPersistRetryTimeout: 1000 }); | ||
const manager = new ObservableManager({ defaultPersistDebounceTimeout: 100, defaultPersistRetryTimeout: 1000 }); | ||
manager.setChannelClient(channel); | ||
return { channel, manager }; | ||
@@ -15,0 +17,0 @@ } |
@@ -21,6 +21,9 @@ import { v4 as uuidV4 } from 'uuid'; | ||
private _options: ObservableManagerOptions; | ||
private _channel: ChannelClient; | ||
private _channel: ChannelClient | null = null; | ||
constructor(channel: ChannelClient, options: ObservableManagerOptions) { | ||
constructor(options: ObservableManagerOptions) { | ||
this._options = options; | ||
} | ||
public setChannelClient(channel: ChannelClient) { | ||
this._channel = channel; | ||
@@ -59,2 +62,6 @@ } | ||
private async requestSnapshot(id: Identity) { | ||
if (!this._channel) { | ||
throw new Error('Channel Client is not set on Observable Manager'); | ||
} | ||
return this._channel.requestSnapshot({ id }); | ||
@@ -64,4 +71,8 @@ } | ||
private async applyPatch(id: Identity, patches: Patch[], revision: number) { | ||
if (!this._channel) { | ||
throw new Error('Channel Client is not set on Observable Manager'); | ||
} | ||
return this._channel.applyPatch({ id, patches, revision }); | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
81597
1483