diff options
author | yipstanley <stanley_yip@brown.edu> | 2019-02-11 00:28:48 -0500 |
---|---|---|
committer | yipstanley <stanley_yip@brown.edu> | 2019-02-11 00:28:48 -0500 |
commit | ab6fe5dbe625bca862558557224d6b5f8d2e5f1d (patch) | |
tree | b85114a770ed44a6ac2120dbb8dcfc0bdc48e5ff /src/client/SocketStub.ts | |
parent | 5d081dc8ea638f9729058bfe7a310cebbd9f5581 (diff) |
asdfkjlasdfljkagit add -A!
Diffstat (limited to 'src/client/SocketStub.ts')
-rw-r--r-- | src/client/SocketStub.ts | 30 |
1 files changed, 11 insertions, 19 deletions
diff --git a/src/client/SocketStub.ts b/src/client/SocketStub.ts index 58dedbf82..3b1401632 100644 --- a/src/client/SocketStub.ts +++ b/src/client/SocketStub.ts @@ -2,6 +2,9 @@ import { Field, FIELD_ID } from "../fields/Field" import { Key, KeyStore } from "../fields/Key" import { ObservableMap, action } from "mobx"; import { Document } from "../fields/Document" +import { MessageStore, SetFieldArgs, GetFieldArgs } from "../server/Message"; +import { Utils } from "../Utils"; +import { Server } from "./Server"; export class SocketStub { @@ -17,25 +20,14 @@ export class SocketStub { // 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, (f as Field).Id)); - } - - public static SEND_FIELD_REQUEST(fieldid: FIELD_ID, callback: (field: Field) => void, timeout: number) { - - if (timeout < 0)// this is a hack to make things easier to setup until we have a server... won't be neededa fter that. - callback(this.FieldStore.get(fieldid) as Field); - else { // actual logic here... - - // Send a request for fieldid to the server - // ...SOCKET(RETRIEVE_FIELD, fieldid) - - // server responds (simulated with a timeout) and the callback is invoked - setTimeout(() => - - // when the field data comes back, call the callback() function - callback(this.FieldStore.get(fieldid) as Field), + // Server.Socket.emit(MessageStore.AddDocument.Message, document) + } - timeout); + public static SEND_FIELD_REQUEST(fieldid: FIELD_ID, callback: (field: Field) => void) { + if (fieldid) { + let args: GetFieldArgs = new GetFieldArgs(fieldid) + Utils.EmitCallback(Server.Socket, MessageStore.GetField, args, (field: Field) => callback(field)) } } @@ -72,7 +64,7 @@ export class SocketStub { // ...SOCKET(SET_FIELD, field id, serialized field value) // Server updates the value of the field in its fieldstore - if (this.FieldStore.get(field.Id)) - this.FieldStore.get(field.Id)!.TrySetValue(value); + let msg: SetFieldArgs = new SetFieldArgs(field.Id as string, value) + Utils.Emit(Server.Socket, MessageStore.SetField, msg) } } |