aboutsummaryrefslogtreecommitdiff
path: root/src/client/DocServer.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/DocServer.ts')
-rw-r--r--src/client/DocServer.ts22
1 files changed, 13 insertions, 9 deletions
diff --git a/src/client/DocServer.ts b/src/client/DocServer.ts
index 5af89cf49..bf5168c22 100644
--- a/src/client/DocServer.ts
+++ b/src/client/DocServer.ts
@@ -27,17 +27,18 @@ export namespace DocServer {
// indicates whether or not a document is currently being udpated, and, if so, its id
export enum WriteMode {
- Always = 0,
- None = 1,
- SameUser = 2,
+ Default = 0, //Anything goes
+ Playground = 1,
+ LiveReadonly = 2,
+ LivePlayground = 3,
}
const fieldWriteModes: { [field: string]: WriteMode } = {};
- const docsWithUpdates: { [field: string]: Doc[] } = {};
+ const docsWithUpdates: { [field: string]: Set<Doc> } = {};
export function setFieldWriteMode(field: string, writeMode: WriteMode) {
fieldWriteModes[field] = writeMode;
- if (writeMode === WriteMode.Always) {
+ if (writeMode !== WriteMode.Playground) {
const docs = docsWithUpdates[field];
if (docs) {
docs.forEach(doc => Doc.RunCachedUpdate(doc, field));
@@ -47,15 +48,18 @@ export namespace DocServer {
}
export function getFieldWriteMode(field: string) {
- return fieldWriteModes[field];
+ return fieldWriteModes[field] || WriteMode.Default;
}
- export function registerDocWithCachedUpdate(doc: Doc, field: string) {
+ export function registerDocWithCachedUpdate(doc: Doc, field: string, oldValue: any) {
let list = docsWithUpdates[field];
if (!list) {
- list = docsWithUpdates[field] = [];
+ list = docsWithUpdates[field] = new Set;
+ }
+ if (!list.has(doc)) {
+ Doc.AddCachedUpdate(doc, field, oldValue);
+ list.add(doc);
}
- list.push(doc);
}
export function init(protocol: string, hostname: string, port: number, identifier: string) {