aboutsummaryrefslogtreecommitdiff
path: root/src/client
diff options
context:
space:
mode:
Diffstat (limited to 'src/client')
-rw-r--r--src/client/Server.ts20
-rw-r--r--src/client/SocketStub.ts58
-rw-r--r--src/client/northstar/dash-fields/HistogramField.ts5
3 files changed, 15 insertions, 68 deletions
diff --git a/src/client/Server.ts b/src/client/Server.ts
index 3bbbebe72..66e9878d9 100644
--- a/src/client/Server.ts
+++ b/src/client/Server.ts
@@ -12,7 +12,6 @@ export class Server {
static Socket: SocketIOClient.Socket = OpenSocket(`${window.location.protocol}//${window.location.hostname}:4321`);
static GUID: string = Utils.GenerateGuid();
-
// Retrieves the cached value of the field and sends a request to the server for the real value (if it's not cached).
// Call this is from within a reaction and test whether the return value is FieldWaiting.
public static GetField(fieldid: FieldId): Promise<Opt<Field>>;
@@ -127,13 +126,6 @@ export class Server {
}
}
- public static AddDocument(document: Document) {
- SocketStub.SEND_ADD_DOCUMENT(document);
- }
- public static AddDocumentField(doc: Document, key: Key, value: Field) {
- console.log("Add doc field " + doc.Title + " " + key.Name + " fid " + value.Id + " " + value);
- SocketStub.SEND_ADD_DOCUMENT_FIELD(doc, key, value);
- }
public static DeleteDocumentField(doc: Document, key: Key) {
SocketStub.SEND_DELETE_DOCUMENT_FIELD(doc, key);
}
@@ -161,18 +153,18 @@ export class Server {
}
@action
- static updateField(field: { _id: string, data: any, type: Types }) {
- if (Server.ClientFieldsCached.has(field._id)) {
- var f = Server.ClientFieldsCached.get(field._id);
+ static updateField(field: { id: string, data: any, type: Types }) {
+ if (Server.ClientFieldsCached.has(field.id)) {
+ var f = Server.ClientFieldsCached.get(field.id);
if (f) {
- // console.log("Applying : " + field._id);
+ // console.log("Applying : " + field.id);
f.UpdateFromServer(field.data);
f.init(emptyFunction);
} else {
- // console.log("Not applying wa : " + field._id);
+ // console.log("Not applying wa : " + field.id);
}
} else {
- // console.log("Not applying mi : " + field._id);
+ // console.log("Not applying mi : " + field.id);
}
}
}
diff --git a/src/client/SocketStub.ts b/src/client/SocketStub.ts
index 5e2ca6a98..382a81f66 100644
--- a/src/client/SocketStub.ts
+++ b/src/client/SocketStub.ts
@@ -2,7 +2,7 @@ import { Key } from "../fields/Key";
import { Field, FieldId, Opt } from "../fields/Field";
import { ObservableMap } from "mobx";
import { Document } from "../fields/Document";
-import { MessageStore, DocumentTransfer } from "../server/Message";
+import { MessageStore, Transferable } from "../server/Message";
import { Utils } from "../Utils";
import { Server } from "./Server";
import { ServerUtils } from "../server/ServerUtil";
@@ -16,35 +16,12 @@ export interface FieldMap {
export class SocketStub {
static FieldStore: ObservableMap<FieldId, Field> = new ObservableMap();
- public static SEND_ADD_DOCUMENT(document: Document) {
-
- // Send a serialized version of the document to the server
- // ...SOCKET(ADD_DOCUMENT, serialied document)
-
- // server stores each document field in its repository of stored fields
- // document.fields.forEach((f, key) => this.FieldStore.set((f as Field).Id, f as Field));
- // let strippedDoc = new Document(document.Id);
- // document.fields.forEach((f, key) => {
- // if (f) {
- // // let args: SetFieldArgs = new SetFieldArgs(f.Id, f.GetValue())
- // let args: Transferable = f.ToJson()
- // Utils.Emit(Server.Socket, MessageStore.SetField, args)
- // }
- // })
-
- // // server stores stripped down document (w/ only field id proxies) in the field store
- // this.FieldStore.set(document.Id, new Document(document.Id));
- // document.fields.forEach((f, key) => (this.FieldStore.get(document.Id) as Document)._proxies.set(key.Id, (f as Field).Id));
-
- console.log("sending " + document.Title);
- Utils.Emit(Server.Socket, MessageStore.AddDocument, new DocumentTransfer(document.ToJson()));
- }
public static SEND_FIELD_REQUEST(fieldid: FieldId): Promise<Opt<Field>>;
public static SEND_FIELD_REQUEST(fieldid: FieldId, callback: (field: Opt<Field>) => void): void;
public static SEND_FIELD_REQUEST(fieldid: FieldId, callback?: (field: Opt<Field>) => void): Promise<Opt<Field>> | void {
let fn = function (cb: (field: Opt<Field>) => void) {
- Utils.EmitCallback(Server.Socket, MessageStore.GetField, fieldid, (field: any) => {
+ Utils.EmitCallback(Server.Socket, MessageStore.GetField, fieldid, (field: Transferable) => {
if (field) {
ServerUtils.FromJson(field).init(cb);
} else {
@@ -60,36 +37,15 @@ export class SocketStub {
}
public static SEND_FIELDS_REQUEST(fieldIds: FieldId[], callback: (fields: FieldMap) => any) {
- Utils.EmitCallback(Server.Socket, MessageStore.GetFields, fieldIds, (fields: any[]) => {
- let fieldMap: any = {};
- let proms: Promise<any>[] = [];
- for (let field of fields) {
- let f = ServerUtils.FromJson(field);
- fieldMap[field._id] = f;
- proms.push(new Promise(res => f.init(res)));
- }
+ Utils.EmitCallback(Server.Socket, MessageStore.GetFields, fieldIds, (fields: Transferable[]) => {
+ let fieldMap: FieldMap = {};
+ fields.map(field => fieldMap[field.id] = ServerUtils.FromJson(field));
+ let proms = Object.values(fieldMap).map(val =>
+ new Promise(resolve => val!.init(resolve)));
Promise.all(proms).then(() => callback(fieldMap));
});
}
- public static SEND_ADD_DOCUMENT_FIELD(doc: Document, key: Key, value: Field) {
-
- // Send a serialized version of the field to the server along with the
- // associated info of the document id and key where it is used.
-
- // ...SOCKET(ADD_DOCUMENT_FIELD, document id, key id, serialized field)
-
- // server updates its document to hold a proxy mapping from key => fieldId
- var document = this.FieldStore.get(doc.Id) as Document;
- if (document) {
- document._proxies.set(key.Id, value.Id);
- }
-
- // server adds the field to its repository of fields
- this.FieldStore.set(value.Id, value);
- // Utils.Emit(Server.Socket, MessageStore.AddDocument, new DocumentTransfer(doc.ToJson()))
- }
-
public static SEND_DELETE_DOCUMENT_FIELD(doc: Document, key: Key) {
// Send a request to delete the field stored under the specified key from the document
diff --git a/src/client/northstar/dash-fields/HistogramField.ts b/src/client/northstar/dash-fields/HistogramField.ts
index 6abde4677..82de51d56 100644
--- a/src/client/northstar/dash-fields/HistogramField.ts
+++ b/src/client/northstar/dash-fields/HistogramField.ts
@@ -35,12 +35,11 @@ export class HistogramField extends BasicField<HistogramOperation> {
}
- ToJson(): { type: Types, data: string, _id: string } {
+ ToJson() {
return {
type: Types.HistogramOp,
-
data: this.toString(),
- _id: this.Id
+ id: this.Id
};
}