diff options
author | laurawilsonri <laura_wilson@brown.edu> | 2019-04-11 14:12:49 -0400 |
---|---|---|
committer | laurawilsonri <laura_wilson@brown.edu> | 2019-04-11 14:12:49 -0400 |
commit | c392a9322c1df269cfd823dd82d07d991fe065c0 (patch) | |
tree | fdd44c511bd179984dc3dc18b92745751c86bfc5 /src/fields/Document.ts | |
parent | 15514b0f3d685764d1bd7ebeac9cdee1f778e184 (diff) | |
parent | 50be8cb7a93110821c972c679567ddb6aae8bc6f (diff) |
Merge branch 'master' of https://github.com/browngraphicslab/Dash-Web into richTextEditor
Diffstat (limited to 'src/fields/Document.ts')
-rw-r--r-- | src/fields/Document.ts | 61 |
1 files changed, 25 insertions, 36 deletions
diff --git a/src/fields/Document.ts b/src/fields/Document.ts index 02004678d..60eaf5b51 100644 --- a/src/fields/Document.ts +++ b/src/fields/Document.ts @@ -16,10 +16,7 @@ import { HistogramField } from "../client/northstar/dash-fields/HistogramField"; export class Document extends Field { //TODO tfs: We should probably store FieldWaiting in fields when we request it from the server so that we don't set up multiple server gets for the same document and field - public fields: ObservableMap< - string, - { key: Key; field: Field } - > = new ObservableMap(); + public fields: ObservableMap<string, { key: Key; field: Field }> = new ObservableMap(); public _proxies: ObservableMap<string, FieldId> = new ObservableMap(); constructor(id?: string, save: boolean = true) { @@ -37,34 +34,24 @@ export class Document extends Field { } } - public Width = () => { - return this.GetNumber(KeyStore.Width, 0); - }; - public Height = () => { - return this.GetNumber( - KeyStore.Height, - this.GetNumber(KeyStore.NativeWidth, 0) - ? (this.GetNumber(KeyStore.NativeHeight, 0) / - this.GetNumber(KeyStore.NativeWidth, 0)) * - this.GetNumber(KeyStore.Width, 0) - : 0 - ); - }; - public Scale = () => { - return this.GetNumber(KeyStore.Scale, 1); - }; + public Width = () => this.GetNumber(KeyStore.Width, 0); + public Height = () => this.GetNumber(KeyStore.Height, this.GetNumber(KeyStore.NativeWidth, 0) ? (this.GetNumber(KeyStore.NativeHeight, 0) / this.GetNumber(KeyStore.NativeWidth, 0)) * this.GetNumber(KeyStore.Width, 0) : 0); + public Scale = () => this.GetNumber(KeyStore.Scale, 1); @computed public get Title(): string { let title = this.Get(KeyStore.Title, true); - if (title) - if (title != FieldWaiting && title instanceof TextField) + if (title) { + if (title !== FieldWaiting && title instanceof TextField) { return title.Data; + } else return "-waiting-"; + } let parTitle = this.GetT(KeyStore.Title, TextField); - if (parTitle) - if (parTitle != FieldWaiting) return parTitle.Data + ".alias"; + if (parTitle) { + if (parTitle !== FieldWaiting) return parTitle.Data + ".alias"; else return "-waiting-.alias"; + } return "-untitled-"; } @@ -109,7 +96,7 @@ export class Document extends Field { } } else { let doc: FieldValue<Document> = this; - while (doc && doc != FieldWaiting && field != FieldWaiting) { + while (doc && field !== FieldWaiting) { let curField = doc.fields.get(key.Id); let curProxy = doc._proxies.get(key.Id); if (!curField || (curProxy && curField.field.Id !== curProxy)) { @@ -140,7 +127,7 @@ export class Document extends Field { break; } } - if (doc == FieldWaiting) field = FieldWaiting; + if (doc === FieldWaiting) field = FieldWaiting; } return field; @@ -194,7 +181,7 @@ export class Document extends Field { if (callback) { fn(callback); } else { - return new Promise(res => fn(res)); + return new Promise(fn); } } @@ -240,7 +227,7 @@ export class Document extends Field { ignoreProto: boolean = false ): FieldValue<T> { var getfield = this.Get(key, ignoreProto); - if (getfield != FieldWaiting) { + if (getfield !== FieldWaiting) { return Cast(getfield, ctor); } return FieldWaiting; @@ -252,7 +239,7 @@ export class Document extends Field { ignoreProto: boolean = false ): T { const field = this.GetT(key, ctor, ignoreProto); - if (field && field != FieldWaiting) { + if (field && field !== FieldWaiting) { return field; } const newField = new ctor(); @@ -362,7 +349,7 @@ export class Document extends Field { GetAllPrototypes(): Document[] { let protos: Document[] = []; let doc: FieldValue<Document> = this; - while (doc && doc != FieldWaiting) { + while (doc && doc !== FieldWaiting) { protos.push(doc); doc = doc.GetPrototype(); } @@ -411,11 +398,13 @@ export class Document extends Field { } } else - if (field instanceof Document) // ... TODO bcz: should we copy documents or reference them - copy.Set(key!, field) - else if (field) - copy.Set(key!, field.Copy()) - }) + if (field instanceof Document) { // ... TODO bcz: should we copy documents or reference them + copy.Set(key!, field); + } + else if (field) { + copy.Set(key!, field.Copy()); + } + }); } }); return copy; @@ -425,7 +414,7 @@ export class Document extends Field { let fields: [string, string][] = []; this._proxies.forEach((field, key) => { if (field) { - fields.push([key, field as string]); + fields.push([key, field]); } }); |