From 4ac7a62d813738b0047caefbcf40d3063ec9e6c1 Mon Sep 17 00:00:00 2001 From: bobzel Date: Tue, 5 Feb 2019 22:37:46 -0500 Subject: checkpoint --- src/fields/Document.ts | 74 ++++++++++++++++++++---------------------------- src/fields/ImageField.ts | 4 +-- 2 files changed, 33 insertions(+), 45 deletions(-) (limited to 'src/fields') diff --git a/src/fields/Document.ts b/src/fields/Document.ts index 0356959a5..5e9c3a707 100644 --- a/src/fields/Document.ts +++ b/src/fields/Document.ts @@ -20,43 +20,35 @@ export class Document extends Field { this.fields.set(key, sfield); } + @observable + GetFieldFromServerDeferred(key: Key) { + var me = this; + setTimeout(function () { + if (me) { + me.DeferredSetField(key); + } + }, key == KeyStore.Data ? 5000 : key == KeyStore.X ? 2500 : 500) + } + @observable GetField(key: Key, ignoreProto: boolean = false): Opt { - if (KeyStore.X == key) { - console.log(""); - } - let field: Opt; + let field: Opt = WAITING; if (ignoreProto) { if (this.fields.has(key)) { - if (KeyStore.X == key) { - console.log(""); - } field = this.fields.get(key); } else { - field = WAITING; - var me = this; - setTimeout(function () { - me.DeferredSetField(key); - }, 100) + this.GetFieldFromServerDeferred(key); // bcz: only want to do this if the field is on the server } } else { let doc: Opt = this; while (doc && doc != WAITING) { - if (!(doc.fields.has(key))) { - var me = this; - setTimeout(function () { - me.DeferredSetField(key); - }, 1000) + if (!doc.fields.has(key)) { + doc.GetFieldFromServerDeferred(key); // bcz: only want to do this if the field is on the server doc = doc.GetPrototype(); - } else + } else { + field = doc.fields.get(key); break; - } - - if (doc && doc != WAITING) { - if (KeyStore.X == key) { - console.log(""); } - field = doc.fields.get(key); } } @@ -67,7 +59,7 @@ export class Document extends Field { GetFieldT(key: Key, ctor: { new(...args: any[]): T }, ignoreProto: boolean = false): Opt { var getfield = this.GetField(key, ignoreProto); if (getfield != WAITING) { - return Cast(this.GetField(key, ignoreProto), ctor); + return Cast(getfield, ctor); } return WAITING; } @@ -105,49 +97,45 @@ export class Document extends Field { return this.GetFieldValue>(key, ListField, defaultVal) } + @action SetField(key: Key, field: Field | undefined): void { if (field) { - if (KeyStore.X == key) { - console.log(""); - } this.fields.set(key, field); } else { this.fields.delete(key); } } + @action SetFieldValue(key: Key, value: any, ctor: { new(): T }): boolean { - if (KeyStore.X == key) { - console.log(""); - } let field = new ctor(); if (field.TrySetValue(value)) { this._sfields.set(key, field); return true; - } else { - return false; } + return false; // let field = this.GetField(key, true); - // if (field == WAITING) - // return true; - // if (field != null) { - // return field.TrySetValue(value); - // } else { - // field = new ctor(); - // if (field.TrySetValue(value)) { - // this.SetField(key, field); - // return true; + // if (field != WAITING) { + // if (field) { + // return field.TrySetValue(value); // } else { - // return false; + // field = new ctor(); + // if (field.TrySetValue(value)) { + // this.SetField(key, field); + // return true; + // } // } // } + // return false; } + @observable GetPrototype(): Opt { return this.GetFieldT(KeyStore.Prototype, Document, true); } + @observable GetAllPrototypes(): Document[] { let protos: Document[] = []; let doc: Opt = this; diff --git a/src/fields/ImageField.ts b/src/fields/ImageField.ts index 9bfacf231..bc2e7cdf4 100644 --- a/src/fields/ImageField.ts +++ b/src/fields/ImageField.ts @@ -2,8 +2,8 @@ import { BasicField } from "./BasicField"; import { Field } from "./Field"; export class ImageField extends BasicField { - constructor(data: URL) { - super(data); + constructor(data: URL | undefined = undefined) { + super(data == undefined ? new URL("http://cs.brown.edu/~bcz/face.gif") : data); } toString(): string { -- cgit v1.2.3-70-g09d2