diff options
author | yipstanley <stanley_yip@brown.edu> | 2019-02-13 20:17:21 -0500 |
---|---|---|
committer | yipstanley <stanley_yip@brown.edu> | 2019-02-13 20:17:21 -0500 |
commit | f3544f004a696e4682fbd8d1f18ac69beec59439 (patch) | |
tree | 0839c355fe813ba494c6451b9017c5e325e1cfb8 /src/client/Server.ts | |
parent | 430878f6dd8d36b1322e15d0898ada0d44fecacb (diff) |
asdfkj
Diffstat (limited to 'src/client/Server.ts')
-rw-r--r-- | src/client/Server.ts | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/src/client/Server.ts b/src/client/Server.ts index a08fc2e87..fab51ca9c 100644 --- a/src/client/Server.ts +++ b/src/client/Server.ts @@ -20,7 +20,9 @@ export class Server { this.ClientFieldsCached.set(fieldid, FieldWaiting); //simulating a server call with a registered callback action SocketStub.SEND_FIELD_REQUEST(fieldid, - action((field: Field) => callback(Server.cacheField(field)))); + action((field: Field) => { + callback(Server.cacheField(field)) + })); } else if (this.ClientFieldsCached.get(fieldid) != FieldWaiting) { callback(this.ClientFieldsCached.get(fieldid) as Field); } @@ -29,14 +31,24 @@ export class Server { static times = 0; // hack for testing public static GetDocumentField(doc: Document, key: Key) { - var hackTimeout: number = key == KeyStore.Data ? (this.times++ == 0 ? 5000 : 1000) : key == KeyStore.X ? 2500 : 500; + // let keyId: string = element[0] + // let valueId: string = element[1] + // Server.GetField(keyId, (key: Field) => { + // if (key instanceof Key) { + // Server.GetField(valueId, (field: Field) => { + // console.log(field) + // doc.Set(key as Key, field) + // }) + // } + // else { + // console.log("how did you get a key that isnt a key wtf") + // } + // }) return this.GetField(doc._proxies.get(key.Id), action((fieldfromserver: Field) => { - doc._proxies.delete(key.Id); doc.fields.set(key, fieldfromserver); - }) - , hackTimeout); + })); } public static AddDocument(document: Document) { @@ -48,8 +60,19 @@ export class Server { public static DeleteDocumentField(doc: Document, key: Key) { SocketStub.SEND_DELETE_DOCUMENT_FIELD(doc, key); } + + private static lock: boolean = false; + public static UpdateField(field: Field) { - SocketStub.SEND_SET_FIELD(field); + if (this.lock) { + setTimeout(this.UpdateField, 1000, field) + } + this.lock = true + SocketStub.SEND_SET_FIELD(field, (args: any) => { + if (this.lock) { + this.lock = false + } + }); } static connected(message: string) { |