aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHannah Chow <hannah_chow@brown.edu>2019-02-28 01:09:35 -0500
committerHannah Chow <hannah_chow@brown.edu>2019-02-28 01:09:35 -0500
commit85970142552fb92299abbbfc1ac1b507013689be (patch)
tree6f06054cdeb2e0cb1cccb9182cd1c3a69f7ff9ab /src
parente6265a20f4c5d2619aa06cef6ee9442c0fd6bb41 (diff)
parent9c9aea92d9a330f5826735c3c3e07ec35b325cc2 (diff)
Merge branch 'master' of https://github.com/browngraphicslab/Dash-Web into hannah_linking
Diffstat (limited to 'src')
-rw-r--r--src/fields/Document.ts19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/fields/Document.ts b/src/fields/Document.ts
index 5b91de6ed..0c156b282 100644
--- a/src/fields/Document.ts
+++ b/src/fields/Document.ts
@@ -102,6 +102,25 @@ export class Document extends Field {
return false;
}
+ GetOrCreateAsync<T extends Field>(key: Key, ctor: { new(): T }, callback: (field: T) => void): void {
+ //This currently doesn't deal with prototypes
+ if (this._proxies.has(key.Id)) {
+ Server.GetDocumentField(this, key, (field) => {
+ if (field && field instanceof ctor) {
+ callback(field);
+ } else {
+ let newField = new ctor();
+ this.Set(key, newField);
+ callback(newField);
+ }
+ });
+ } else {
+ let newField = new ctor();
+ this.Set(key, newField);
+ callback(newField);
+ }
+ }
+
GetT<T extends Field = Field>(key: Key, ctor: { new(...args: any[]): T }, ignoreProto: boolean = false): FieldValue<T> {
var getfield = this.Get(key, ignoreProto);
if (getfield != FieldWaiting) {