From 68f613b5e762649b743059e494e9307eb103ff0d Mon Sep 17 00:00:00 2001 From: Tyler Schicke Date: Thu, 8 Aug 2019 16:15:22 -0400 Subject: Fixed per field write modes --- src/new_fields/Doc.ts | 12 ++++++++++-- src/new_fields/util.ts | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) (limited to 'src/new_fields') diff --git a/src/new_fields/Doc.ts b/src/new_fields/Doc.ts index ba01cfd9c..87e048140 100644 --- a/src/new_fields/Doc.ts +++ b/src/new_fields/Doc.ts @@ -148,7 +148,7 @@ export class Doc extends RefField { return "invalid"; } - private [CachedUpdates]: { [key: string]: () => Promise } = {}; + private [CachedUpdates]: { [key: string]: () => void | Promise } = {}; public async [HandleUpdate](diff: any) { const set = diff.$set; @@ -178,7 +178,7 @@ export class Doc extends RefField { continue; } const fKey = key.substring(7); - const fn = async () => { + const fn = () => { updatingFromServer = true; delete this[fKey]; updatingFromServer = false; @@ -211,6 +211,14 @@ export namespace Doc { delete doc[CachedUpdates][field]; } } + export function AddCachedUpdate(doc: Doc, field: string, oldValue: any) { + const val = oldValue; + doc[CachedUpdates][field] = () => { + updatingFromServer = true; + doc[field] = val; + updatingFromServer = false; + }; + } export function MakeReadOnly(): { end(): void } { makeReadOnly(); return { diff --git a/src/new_fields/util.ts b/src/new_fields/util.ts index 099fe2d0a..6c05da507 100644 --- a/src/new_fields/util.ts +++ b/src/new_fields/util.ts @@ -70,7 +70,7 @@ const _setterImpl = action(function (target: any, prop: string | symbol | number if (value === undefined) target[Update]({ '$unset': { ["fields." + prop]: "" } }); else target[Update]({ '$set': { ["fields." + prop]: value instanceof ObjectField ? SerializationHelper.Serialize(value) : (value === undefined ? null : value) } }); } else { - DocServer.registerDocWithCachedUpdate(receiver, prop as string); + DocServer.registerDocWithCachedUpdate(receiver, prop as string, curValue); } UndoManager.AddEvent({ redo: () => receiver[prop] = value, -- cgit v1.2.3-70-g09d2 From 4b358bfc1122f91b907305c15fc4214d7fc74a4c Mon Sep 17 00:00:00 2001 From: Tyler Schicke Date: Fri, 9 Aug 2019 15:01:42 -0400 Subject: Compile errors and Fixed read only modes --- src/client/DocServer.ts | 11 ++++--- src/client/views/MainView.tsx | 17 +++++----- .../views/collections/CollectionSchemaView.tsx | 4 +-- src/new_fields/Doc.ts | 35 +++++++++++--------- src/new_fields/util.ts | 38 +++++++++++++--------- 5 files changed, 59 insertions(+), 46 deletions(-) (limited to 'src/new_fields') diff --git a/src/client/DocServer.ts b/src/client/DocServer.ts index 977eb7772..bf5168c22 100644 --- a/src/client/DocServer.ts +++ b/src/client/DocServer.ts @@ -27,9 +27,10 @@ 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 } = {}; @@ -37,7 +38,7 @@ export namespace DocServer { 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,7 +48,7 @@ export namespace DocServer { } export function getFieldWriteMode(field: string) { - return fieldWriteModes[field]; + return fieldWriteModes[field] || WriteMode.Default; } export function registerDocWithCachedUpdate(doc: Doc, field: string, oldValue: any) { diff --git a/src/client/views/MainView.tsx b/src/client/views/MainView.tsx index 7629a0906..eabb23489 100644 --- a/src/client/views/MainView.tsx +++ b/src/client/views/MainView.tsx @@ -435,7 +435,6 @@ export class MainView extends React.Component { } - private mode: DocServer.WriteMode = DocServer.WriteMode.Always; @observable private _colorPickerDisplay = false; /* for the expandable add nodes menu. Not included with the miscbuttons because once it expands it expands the whole div with it, making canvas interactions limited. */ nodesMenu() { @@ -463,6 +462,11 @@ export class MainView extends React.Component { ]; if (!ClientUtils.RELEASE) btns.unshift([React.createRef(), "cat", "Add Cat Image", addImageNode]); + const setWriteMode = (mode: DocServer.WriteMode) => { + console.log(DocServer.WriteMode[mode]); + DocServer.setFieldWriteMode("x", mode); + DocServer.setFieldWriteMode("y", mode); + }; return < div id="add-nodes-menu" style={{ left: this.flyoutWidth + 20, bottom: 20 }} > @@ -480,13 +484,10 @@ export class MainView extends React.Component { )}
  • -
  • +
  • +
  • +
  • +