mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-11-12 12:40:08 +08:00
083021d860
Summary: This replaces the API delta stream with a direct in-memory one Depends on D3548 Test Plan: manual Reviewers: halla, jackie Reviewed By: halla, jackie Subscribers: juan Differential Revision: https://phab.nylas.com/D3549
52 lines
1.3 KiB
JavaScript
52 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);
|
|
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
|