diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/fields/Document.ts | 23 | ||||
-rw-r--r-- | src/views/collections/CollectionDockingView.tsx | 3 |
2 files changed, 22 insertions, 4 deletions
diff --git a/src/fields/Document.ts b/src/fields/Document.ts index 9580ab5c0..0551a74b0 100644 --- a/src/fields/Document.ts +++ b/src/fields/Document.ts @@ -1,5 +1,6 @@ import { Field, Cast, Opt } from "./Field" import { Key, KeyStore } from "./Key" +import { NumberField } from "./NumberField"; import { ObservableMap, computed } from "mobx"; import { TextField } from "./TextField"; @@ -30,17 +31,35 @@ export class Document extends Field { return field; } - GetFieldT<T extends Field = Field>(key: Key, ctor: { new(): T }, ignoreProto?: boolean): Opt<T> { + GetFieldT<T extends Field = Field>(key: Key, ctor: { new(): T }, ignoreProto: boolean = false): Opt<T> { return Cast(this.GetField(key, ignoreProto), ctor); } + GetFieldOrCreate<T extends Field>(key: Key, ctor: { new(): T }, ignoreProto: boolean = false): T { + const field = this.GetFieldT(key, ctor, ignoreProto); + if (field) { + return field; + } + const newField = new ctor(); + this.SetField(key, newField); + return newField; + } + GetFieldValue<T, U extends { Data: T }>(key: Key, ctor: { new(): U }, defaultVal: T): T { let val = this.GetField(key); let vval = (val && val instanceof ctor) ? val.Data : defaultVal; return vval; } - SetField(key: Key, field: Opt<Field>): void { + GetNumberValue(key: Key, defaultVal: number): number { + return this.GetFieldValue(key, NumberField, defaultVal); + } + + GetTextValue(key: Key, defaultVal: string): string { + return this.GetFieldValue(key, TextField, defaultVal); + } + + SetField(key: Key, field: Field | undefined): void { if (field) { this.fields.set(key, field); } else { diff --git a/src/views/collections/CollectionDockingView.tsx b/src/views/collections/CollectionDockingView.tsx index fd492503d..3d0c39c9d 100644 --- a/src/views/collections/CollectionDockingView.tsx +++ b/src/views/collections/CollectionDockingView.tsx @@ -43,8 +43,7 @@ export class CollectionDockingView extends React.Component<CollectionViewProps> const { fieldKey, Document: Document } = this.props; const value: Document[] = Document.GetFieldValue(fieldKey, ListField, []); var docs = value.map(doc => { - var d = { type: 'component', componentName: 'documentViewComponent', componentState: { doc: doc } }; - return d; + return { type: 'component', componentName: 'documentViewComponent', componentState: { doc: doc } }; }); return new GoldenLayout({ content: [ { type: 'row', content: docs } ] }); } |