aboutsummaryrefslogtreecommitdiff
path: root/src/client/Server.ts
diff options
context:
space:
mode:
authoryipstanley <stanley_yip@brown.edu>2019-04-13 17:37:15 -0400
committeryipstanley <stanley_yip@brown.edu>2019-04-13 17:37:15 -0400
commit0a3fb59c91ad0498fe0302522ea775f71483d9e7 (patch)
treed5ad95a3ff978b89b1978017f921f58aec2eb884 /src/client/Server.ts
parent191283a0e61e1f1b81429e6be6c5c1ef3da1a1b1 (diff)
parenta23b160d19beff9163f970f7ae678c2aed9ce14e (diff)
Merge branch 'master' of https://github.com/browngraphicslab/Dash-Web into interaction_changes
Diffstat (limited to 'src/client/Server.ts')
-rw-r--r--src/client/Server.ts26
1 files changed, 13 insertions, 13 deletions
diff --git a/src/client/Server.ts b/src/client/Server.ts
index 857101a33..3bbbebe72 100644
--- a/src/client/Server.ts
+++ b/src/client/Server.ts
@@ -1,10 +1,10 @@
import { Key } from "../fields/Key";
-import { ObservableMap, action, reaction } from "mobx";
+import { ObservableMap, action, reaction, runInAction } from "mobx";
import { Field, FieldWaiting, FIELD_WAITING, Opt, FieldId } from "../fields/Field";
import { Document } from "../fields/Document";
import { SocketStub, FieldMap } from "./SocketStub";
import * as OpenSocket from 'socket.io-client';
-import { Utils } from "./../Utils";
+import { Utils, emptyFunction } from "./../Utils";
import { MessageStore, Types } from "./../server/Message";
export class Server {
@@ -59,14 +59,14 @@ export class Server {
public static GetFields(fieldIds: FieldId[]): Promise<{ [id: string]: Field }>;
public static GetFields(fieldIds: FieldId[], callback: (fields: FieldMap) => any): void;
public static GetFields(fieldIds: FieldId[], callback?: (fields: FieldMap) => any): Promise<FieldMap> | void {
- let fn = (cb: (fields: FieldMap) => void) => {
+ let fn = action((cb: (fields: FieldMap) => void) => {
let neededFieldIds: FieldId[] = [];
let waitingFieldIds: FieldId[] = [];
- let existingFields: { [id: string]: Field } = {};
+ let existingFields: FieldMap = {};
for (let id of fieldIds) {
let field = this.ClientFieldsCached.get(id);
- if (!field) {
+ if (field === undefined) {
neededFieldIds.push(id);
this.ClientFieldsCached.set(id, FieldWaiting);
} else if (field === FieldWaiting) {
@@ -79,7 +79,7 @@ export class Server {
for (let id of neededFieldIds) {
let field = fields[id];
if (field) {
- if (!(this.ClientFieldsCached.get(field.Id) instanceof Field)) {
+ if (this.ClientFieldsCached.get(field.Id) === FieldWaiting) {
this.ClientFieldsCached.set(field.Id, field);
} else {
throw new Error("we shouldn't be trying to replace things that are already in the cache");
@@ -94,17 +94,17 @@ export class Server {
}
reaction(() => waitingFieldIds.map(id => this.ClientFieldsCached.get(id)),
(cachedFields, reaction) => {
- if (!cachedFields.some(field => !field)) {
+ if (!cachedFields.some(field => field === FieldWaiting)) {
+ const realFields = cachedFields as Opt<Field>[];
reaction.dispose();
- for (let field of cachedFields) {
- let realField = field as Field;
- existingFields[realField.Id] = realField;
- }
+ waitingFieldIds.forEach((id, index) => {
+ existingFields[id] = realFields[index];
+ });
cb({ ...fields, ...existingFields });
}
}, { fireImmediately: true });
}));
- };
+ });
if (callback) {
fn(callback);
} else {
@@ -167,7 +167,7 @@ export class Server {
if (f) {
// console.log("Applying : " + field._id);
f.UpdateFromServer(field.data);
- f.init(() => { });
+ f.init(emptyFunction);
} else {
// console.log("Not applying wa : " + field._id);
}