aboutsummaryrefslogtreecommitdiff
path: root/src/client/SocketStub.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/SocketStub.ts')
-rw-r--r--src/client/SocketStub.ts28
1 files changed, 22 insertions, 6 deletions
diff --git a/src/client/SocketStub.ts b/src/client/SocketStub.ts
index 03c0131ba..7545a166c 100644
--- a/src/client/SocketStub.ts
+++ b/src/client/SocketStub.ts
@@ -1,10 +1,11 @@
-import { Field, FIELD_ID } from "../fields/Field"
+import { Field, FIELD_ID, Opt } from "../fields/Field"
import { Key, KeyStore } from "../fields/Key"
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 {
@@ -32,13 +33,28 @@ export class SocketStub {
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
@@ -67,12 +83,12 @@ export class SocketStub {
document._proxies.delete(key.Id);
}
- public static SEND_SET_FIELD(field: Field) {
+ public static SEND_SET_FIELD(field: Field, fn: (args: any) => void) {
// Send a request to set the value of a field
// ...SOCKET(SET_FIELD, field id, serialized field value)
// Server updates the value of the field in its fieldstore
- Utils.Emit(Server.Socket, MessageStore.SetField, field.ToJson())
+ Utils.EmitCallback(Server.Socket, MessageStore.SetField, field.ToJson(), fn)
}
}