Mailspring/packages/client-app/internal_packages/deltas/lib/delta-streaming-in-memory-connection.es6
Evan Morikawa 12236753d5 [client-app] only show cloud deltas in the developer bar
Summary:
This removes client-sync deltas from the developerbar delta list.

We ONLY show cloud deltas now.

The connection between client-sync is no longer a network delta stream,
it's a direct function call. It makes no sense to show its status.

This now shows a single dot representing the state of the cloud delta
stream.

Test Plan: Manually connect and disconnect local cloud API and see icon change

Reviewers: halla, spang, juan

Reviewed By: juan

Differential Revision: https://phab.nylas.com/D3977
2017-02-17 17:33:18 -08:00

53 lines
1.3 KiB
JavaScript

/**
* This implements the same interface as the DeltaStreamingConnection
*/
class DeltaStreamingInMemoryConnection {
constructor(accountId, opts) {
this._accountId = accountId
this._getCursor = opts.getCursor
this._setCursor = opts.setCursor
this._onDeltas = opts.onDeltas
this._onStatusChanged = opts.onStatusChanged
this._status = "none"
}
onDeltas = (allDeltas = []) => {
const deltas = allDeltas.filter((d) => d.accountId === this._accountId);
this._onDeltas(deltas, {source: "localSync"});
const last = deltas[deltas.length - 1]
if (last) this._setCursor(last.cursor);
}
get accountId() {
return this._accountId;
}
get status() {
return this._status;
}
setStatus(status) {
this._status = status
this._onStatusChanged(status)
}
start() {
this._disp = NylasEnv.localSyncEmitter.on("localSyncDeltas", this.onDeltas);
NylasEnv.localSyncEmitter.emit("startDeltasFor", {
cursor: this._getCursor() || 0,
accountId: this._accountId,
})
this.setStatus("connected")
}
end() {
if (this._disp && this._disp.dispose) this._disp.dispose()
NylasEnv.localSyncEmitter.emit("endDeltasFor", {
accountId: this._accountId,
})
this.setStatus("ended")
}
}
export default DeltaStreamingInMemoryConnection