mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) move client code to core
Summary: This moves all client code to core, and makes minimal fix-ups to get grist and grist-core to compile correctly. The client works in core, but I'm leaving clean-up around the build and bundles to follow-up. Test Plan: existing tests pass; server-dev bundle looks sane Reviewers: dsagal Reviewed By: dsagal Differential Revision: https://phab.getgrist.com/D2627
This commit is contained in:
41
app/client/models/ConnectState.ts
Normal file
41
app/client/models/ConnectState.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* The ConnectStateManager helper class helps maintain the connection state. A disconnect goes
|
||||
* through multiple stages, to inform the user of long disconnects while minimizing the disruption
|
||||
* for short ones. This class manages these timings, and triggers ConnectState changes.
|
||||
*/
|
||||
import {Disposable, Observable} from 'grainjs';
|
||||
|
||||
// Describes the connection state, which is shown as part of the notifications UI.
|
||||
// See https://grist.quip.com/X92IAHZV3uoo/Notifications
|
||||
export enum ConnectState { Connected, JustDisconnected, RecentlyDisconnected, ReallyDisconnected }
|
||||
|
||||
export class ConnectStateManager extends Disposable {
|
||||
// On disconnect, ConnectState changes to JustDisconnected. These intervals set how long after
|
||||
// the disconnect ConnectState should change to other values.
|
||||
public static timeToRecentlyDisconnected = 5000;
|
||||
public static timeToReallyDisconnected = 30000;
|
||||
|
||||
public readonly connectState = Observable.create<ConnectState>(this, ConnectState.Connected);
|
||||
|
||||
private _timers: Array<ReturnType<typeof setTimeout>> = [];
|
||||
|
||||
public setConnected(yesNo: boolean) {
|
||||
if (yesNo) {
|
||||
this._timers.forEach((t) => clearTimeout(t));
|
||||
this._timers = [];
|
||||
this._setState(ConnectState.Connected);
|
||||
} else if (this.connectState.get() === ConnectState.Connected) {
|
||||
this._timers = [
|
||||
setTimeout(() => this._setState(ConnectState.RecentlyDisconnected),
|
||||
ConnectStateManager.timeToRecentlyDisconnected),
|
||||
setTimeout(() => this._setState(ConnectState.ReallyDisconnected),
|
||||
ConnectStateManager.timeToReallyDisconnected),
|
||||
];
|
||||
this._setState(ConnectState.JustDisconnected);
|
||||
}
|
||||
}
|
||||
|
||||
private _setState(state: ConnectState) {
|
||||
this.connectState.set(state);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user