aboutsummaryrefslogtreecommitdiff
path: root/src/new_fields/util.ts
diff options
context:
space:
mode:
authorTyler Schicke <tyler_schicke@brown.edu>2019-05-16 20:31:21 -0400
committerTyler Schicke <tyler_schicke@brown.edu>2019-05-16 20:31:21 -0400
commita2333e76fea26d2ce03272947d8a89973489fa46 (patch)
tree99dd3a6755f76d91bb8f1852681d39ff6de94fa5 /src/new_fields/util.ts
parentb29a0d1cef60b55f609fcd94ad38232ae557e681 (diff)
Made KVP not render while documents are loading
Diffstat (limited to 'src/new_fields/util.ts')
-rw-r--r--src/new_fields/util.ts22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/new_fields/util.ts b/src/new_fields/util.ts
index a5f5e368b..3a16a6b42 100644
--- a/src/new_fields/util.ts
+++ b/src/new_fields/util.ts
@@ -55,6 +55,17 @@ export function getter(target: any, prop: string | symbol | number, receiver: an
}
return getField(target, prop);
}
+function getProtoField(protoField: Doc | undefined, prop: string | number, cb?: (field: Field | undefined) => void) {
+ if (!protoField) return undefined;
+ let field = protoField[prop];
+ if (field instanceof Promise) {
+ cb && field.then(cb);
+ return field;
+ } else {
+ cb && cb(field);
+ return field;
+ }
+}
//TODO The callback parameter is never being passed in currently, so we should be able to get rid of it.
export function getField(target: any, prop: string | number, ignoreProto: boolean = false, callback?: (field: Field | undefined) => void): any {
@@ -65,14 +76,9 @@ export function getField(target: any, prop: string | number, ignoreProto: boolea
if (field === undefined && !ignoreProto) {
const proto = getField(target, "proto", true);
if (proto instanceof Doc) {
- let field = proto[prop];
- if (field instanceof Promise) {
- callback && field.then(callback);
- return undefined;
- } else {
- callback && callback(field);
- return field;
- }
+ return getProtoField(proto, prop, callback);
+ } else if (proto instanceof Promise) {
+ return proto.then(async proto => getProtoField(proto, prop, callback));
}
}
callback && callback(field);