aboutsummaryrefslogtreecommitdiff
path: root/src/client/DocServer.ts
diff options
context:
space:
mode:
authorandrewdkim <adkim414@gmail.com>2019-08-12 15:18:19 -0400
committerandrewdkim <adkim414@gmail.com>2019-08-12 15:18:19 -0400
commitbfe1be9425fed19be30ebf21bcdd7eadf5844c28 (patch)
tree0de5874c83a719616413c0c66a39b667a5f42267 /src/client/DocServer.ts
parentc7e258d9d56990daec490b239e4103f9ca9d521a (diff)
parent3aea955ae56c1aa0611de09c4a013e9dc5c86c42 (diff)
pulled from master
Diffstat (limited to 'src/client/DocServer.ts')
-rw-r--r--src/client/DocServer.ts38
1 files changed, 37 insertions, 1 deletions
diff --git a/src/client/DocServer.ts b/src/client/DocServer.ts
index 87a87be92..bf5168c22 100644
--- a/src/client/DocServer.ts
+++ b/src/client/DocServer.ts
@@ -1,6 +1,6 @@
import * as OpenSocket from 'socket.io-client';
import { MessageStore, Diff, YoutubeQueryTypes } from "./../server/Message";
-import { Opt } from '../new_fields/Doc';
+import { Opt, Doc } from '../new_fields/Doc';
import { Utils, emptyFunction } from '../Utils';
import { SerializationHelper } from './util/SerializationHelper';
import { RefField } from '../new_fields/RefField';
@@ -26,6 +26,42 @@ export namespace DocServer {
let GUID: string;
// indicates whether or not a document is currently being udpated, and, if so, its id
+ export enum WriteMode {
+ Default = 0, //Anything goes
+ Playground = 1,
+ LiveReadonly = 2,
+ LivePlayground = 3,
+ }
+
+ const fieldWriteModes: { [field: string]: WriteMode } = {};
+ const docsWithUpdates: { [field: string]: Set<Doc> } = {};
+
+ export function setFieldWriteMode(field: string, writeMode: WriteMode) {
+ fieldWriteModes[field] = writeMode;
+ if (writeMode !== WriteMode.Playground) {
+ const docs = docsWithUpdates[field];
+ if (docs) {
+ docs.forEach(doc => Doc.RunCachedUpdate(doc, field));
+ delete docsWithUpdates[field];
+ }
+ }
+ }
+
+ export function getFieldWriteMode(field: string) {
+ return fieldWriteModes[field] || WriteMode.Default;
+ }
+
+ export function registerDocWithCachedUpdate(doc: Doc, field: string, oldValue: any) {
+ let list = docsWithUpdates[field];
+ if (!list) {
+ list = docsWithUpdates[field] = new Set;
+ }
+ if (!list.has(doc)) {
+ Doc.AddCachedUpdate(doc, field, oldValue);
+ list.add(doc);
+ }
+ }
+
export function init(protocol: string, hostname: string, port: number, identifier: string) {
_cache = {};
GUID = identifier;