aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTyler Schicke <tyler_schicke@brown.edu>2019-08-08 16:15:22 -0400
committerTyler Schicke <tyler_schicke@brown.edu>2019-08-08 16:15:22 -0400
commit68f613b5e762649b743059e494e9307eb103ff0d (patch)
tree10aed3f36b3b006ae83ecbfc1be661d873d6b95d
parent316c241d72fb83aad5f2bf9b143c317fdc906654 (diff)
Fixed per field write modes
-rw-r--r--src/client/DocServer.ts11
-rw-r--r--src/client/views/MainView.tsx17
-rw-r--r--src/new_fields/Doc.ts12
-rw-r--r--src/new_fields/util.ts2
4 files changed, 26 insertions, 16 deletions
diff --git a/src/client/DocServer.ts b/src/client/DocServer.ts
index 5af89cf49..977eb7772 100644
--- a/src/client/DocServer.ts
+++ b/src/client/DocServer.ts
@@ -33,7 +33,7 @@ export namespace DocServer {
}
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;
@@ -50,12 +50,15 @@ export namespace DocServer {
return fieldWriteModes[field];
}
- 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) {
diff --git a/src/client/views/MainView.tsx b/src/client/views/MainView.tsx
index ddb023aca..7629a0906 100644
--- a/src/client/views/MainView.tsx
+++ b/src/client/views/MainView.tsx
@@ -435,6 +435,7 @@ 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() {
@@ -479,15 +480,13 @@ export class MainView extends React.Component {
</button>
</div></li>)}
<li key="undoTest"><button className="add-button round-button" title="Click if undo isn't working" onClick={() => UndoManager.TraceOpenBatches()}><FontAwesomeIcon icon="exclamation" size="sm" /></button></li>
- <li key="test"><button className="add-button round-button" title="asdf" onClick={(() => {
- let state = DocServer.WriteMode.Always;
- return () => {
- state++;
- state = state % 3;
- DocServer.setFieldWriteMode("x", state);
- DocServer.setFieldWriteMode("y", state);
- };
- })()}><FontAwesomeIcon icon="exclamation" size="sm" /></button></li>
+ <li key="test"><button className="add-button round-button" title="asdf" onClick={() => {
+ this.mode++;
+ this.mode = this.mode % 3;
+ console.log(DocServer.WriteMode[this.mode]);
+ DocServer.setFieldWriteMode("x", this.mode);
+ DocServer.setFieldWriteMode("y", this.mode);
+ }}><FontAwesomeIcon icon="exclamation" size="sm" /></button></li>
<li key="color"><button className="add-button round-button" title="Select Color" style={{ zIndex: 1000 }} onClick={() => this.toggleColorPicker()}><div className="toolbar-color-button" style={{ backgroundColor: InkingControl.Instance.selectedColor }} >
<div className="toolbar-color-picker" onClick={this.onColorClick} style={this._colorPickerDisplay ? { color: "black", display: "block" } : { color: "black", display: "none" }}>
<SketchPicker color={InkingControl.Instance.selectedColor} onChange={InkingControl.Instance.switchColor} />
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<any> } = {};
+ private [CachedUpdates]: { [key: string]: () => void | Promise<any> } = {};
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,