aboutsummaryrefslogtreecommitdiff
path: root/src/client/SocketStub.ts
diff options
context:
space:
mode:
authormadelinegr <laura_wilson@brown.edu>2019-02-18 19:38:08 -0500
committermadelinegr <laura_wilson@brown.edu>2019-02-18 19:38:08 -0500
commit6fd2cec91efd6672a70e15a786954f92c1d23416 (patch)
tree0cbf4c1dd399bd041e05eb4c911a642547f673f9 /src/client/SocketStub.ts
parent41ba832136aef2b7e6a5034486757aa4b3047cf9 (diff)
parent70a8b4ab8075af4d06efb04c083b3bf11636373e (diff)
Merge remote-tracking branch 'origin/server_database_merge' into authentication
Diffstat (limited to 'src/client/SocketStub.ts')
-rw-r--r--src/client/SocketStub.ts28
1 files changed, 23 insertions, 5 deletions
diff --git a/src/client/SocketStub.ts b/src/client/SocketStub.ts
index 03c0131ba..2bddf4e97 100644
--- a/src/client/SocketStub.ts
+++ b/src/client/SocketStub.ts
@@ -1,10 +1,12 @@
-import { Field, FIELD_ID } from "../fields/Field"
-import { Key, KeyStore } from "../fields/Key"
+import { Field, FIELD_ID, Opt } from "../fields/Field"
+import { Key } from "../fields/Key"
+import { KeyStore } from "../fields/KeyStore"
import { ObservableMap, action } from "mobx";
import { Document } from "../fields/Document"
import { MessageStore, SetFieldArgs, GetFieldArgs, DocumentTransfer, Types } from "../server/Message";
import { Utils } from "../Utils";
import { Server } from "./Server";
+import { ServerUtils } from "../server/ServerUtil";
export class SocketStub {
@@ -29,16 +31,32 @@ export class SocketStub {
// 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: FIELD_ID, callback: (field: Field) => void) {
+ public static SEND_FIELD_REQUEST(fieldid: FIELD_ID, callback: (field: Opt<Field>) => void) {
if (fieldid) {
- let args: GetFieldArgs = new GetFieldArgs(fieldid)
- Utils.EmitCallback(Server.Socket, MessageStore.GetField, args, (field: Field) => callback(field))
+ Utils.EmitCallback(Server.Socket, MessageStore.GetField, fieldid, (field: any) => {
+ if (field) {
+ ServerUtils.FromJson(field).init(callback);
+ } else {
+ callback(undefined);
+ }
+ })
}
}
+ public static SEND_FIELDS_REQUEST(fieldIds: FIELD_ID[], callback: (fields: { [key: string]: Field }) => any) {
+ Utils.EmitCallback(Server.Socket, MessageStore.GetFields, fieldIds, (fields: any[]) => {
+ let fieldMap: any = {};
+ for (let field of fields) {
+ fieldMap[field._id] = ServerUtils.FromJson(field);
+ }
+ 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