rhine-var
Version:
Variables that support multi-user collaboration and persistence, making collaboration and variable operations as simple as possible, with strict and well-defined type hints.
66 lines (65 loc) • 2.04 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.websocketRhineConnect = websocketRhineConnect;
const connector_status_enum_1 = require("./connector-status.enum");
class Connector {
subscribeSynced(callback) {
this.syncedSubscribers.push(callback);
return () => {
this.unsubscribeSynced(callback);
};
}
unsubscribeSynced(callback) {
this.syncedSubscribers = this.syncedSubscribers.filter((subscriber) => subscriber !== callback);
}
unsubscribeAllSynced() {
this.syncedSubscribers = [];
}
emitSynced(synced) {
this.syncedSubscribers.forEach((subscriber) => {
subscriber(synced);
});
}
afterSynced(callback) {
if (this.synced) {
callback();
}
else {
const subscriber = (synced) => {
if (synced) {
this.unsubscribeSynced(subscriber);
callback();
}
};
this.subscribeSynced(subscriber);
}
}
waitSynced() {
return new Promise((resolve) => {
this.afterSynced(resolve);
});
}
constructor() {
this.yDoc = null;
this.yBaseMap = null;
this.clientId = -1;
this.synced = false;
this.status = connector_status_enum_1.ConnectorStatus.DISCONNECTED;
this.syncedSubscribers = [];
}
hasState() {
var _a, _b;
return (_b = (_a = this.yBaseMap) === null || _a === void 0 ? void 0 : _a.has(Connector.STATE_KEY)) !== null && _b !== void 0 ? _b : false;
}
getState() {
var _a;
return (_a = this.yBaseMap) === null || _a === void 0 ? void 0 : _a.get(Connector.STATE_KEY);
}
setState(state) {
var _a;
(_a = this.yBaseMap) === null || _a === void 0 ? void 0 : _a.set(Connector.STATE_KEY, state);
}
}
Connector.STATE_KEY = 'state';
exports.default = Connector;
function websocketRhineConnect(url) { }