aboutsummaryrefslogtreecommitdiff
path: root/src/client/Server.ts
diff options
context:
space:
mode:
authorlaurawilsonri <laura_wilson@brown.edu>2019-03-18 18:14:27 -0400
committerlaurawilsonri <laura_wilson@brown.edu>2019-03-18 18:14:27 -0400
commit9d939c1190ef86e456cf26e9f5cb84743279f7a6 (patch)
tree24d72d918f2becf6762ea30b92da7339957eedbd /src/client/Server.ts
parent67170e521366f8178645cc85aaf377e53b1a6f21 (diff)
parentf70ad315167b714f11f7d68f35a46abe9e525a4d (diff)
Merge branch 'master' of https://github.com/browngraphicslab/Dash-Web into editableSchema
Diffstat (limited to 'src/client/Server.ts')
-rw-r--r--src/client/Server.ts35
1 files changed, 30 insertions, 5 deletions
diff --git a/src/client/Server.ts b/src/client/Server.ts
index f0cf0bb9b..3fb1ae878 100644
--- a/src/client/Server.ts
+++ b/src/client/Server.ts
@@ -40,8 +40,8 @@ export class Server {
return this.ClientFieldsCached.get(fieldid);
}, (field, reaction) => {
if (field !== "<Waiting>") {
- callback(field)
reaction.dispose()
+ callback(field)
}
})
}
@@ -49,14 +49,39 @@ export class Server {
}
public static GetFields(fieldIds: FieldId[], callback: (fields: { [id: string]: Field }) => any) {
- SocketStub.SEND_FIELDS_REQUEST(fieldIds, (fields) => {
+ let neededFieldIds: FieldId[] = [];
+ let waitingFieldIds: FieldId[] = [];
+ let existingFields: { [id: string]: Field } = {};
+ for (let id of fieldIds) {
+ let field = this.ClientFieldsCached.get(id);
+ if (!field) {
+ neededFieldIds.push(id);
+ this.ClientFieldsCached.set(id, FieldWaiting);
+ } else if (field === FieldWaiting) {
+ waitingFieldIds.push(id);
+ } else {
+ existingFields[id] = field;
+ }
+ }
+ SocketStub.SEND_FIELDS_REQUEST(neededFieldIds, (fields) => {
for (let key in fields) {
let field = fields[key];
- if (!this.ClientFieldsCached.has(field.Id)) {
+ if (!(this.ClientFieldsCached.get(field.Id) instanceof Field)) {
this.ClientFieldsCached.set(field.Id, field)
}
}
- callback(fields)
+ reaction(() => {
+ return waitingFieldIds.map(this.ClientFieldsCached.get);
+ }, (cachedFields, reaction) => {
+ if (!cachedFields.some(field => !field || field === FieldWaiting)) {
+ reaction.dispose();
+ for (let field of cachedFields) {
+ let realField = field as Field;
+ existingFields[realField.Id] = realField;
+ }
+ callback({ ...fields, ...existingFields })
+ }
+ }, { fireImmediately: true })
});
}
@@ -121,4 +146,4 @@ export class Server {
}
Server.Socket.on(MessageStore.Foo.Message, Server.connected);
-Server.Socket.on(MessageStore.SetField.Message, Server.updateField); \ No newline at end of file
+Server.Socket.on(MessageStore.SetField.Message, Server.updateField);