aboutsummaryrefslogtreecommitdiff
path: root/src/new_fields/Doc.ts
diff options
context:
space:
mode:
authorbob <bcz@cs.brown.edu>2019-05-13 10:56:12 -0400
committerbob <bcz@cs.brown.edu>2019-05-13 10:56:12 -0400
commit48b0f98ea2519d861a0eecee541dc0986a2c2f12 (patch)
tree80b6baeeb62989385c7d364639e52817aff93482 /src/new_fields/Doc.ts
parent762394f2d226501a95ba34edebcbea7ba9bf6a47 (diff)
small fixes
Diffstat (limited to 'src/new_fields/Doc.ts')
-rw-r--r--src/new_fields/Doc.ts12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/new_fields/Doc.ts b/src/new_fields/Doc.ts
index 625ba0d6a..a8c9d28e1 100644
--- a/src/new_fields/Doc.ts
+++ b/src/new_fields/Doc.ts
@@ -134,7 +134,8 @@ export namespace Doc {
return Cast(Get(doc, key, ignoreProto), ctor) as FieldResult<T>;
}
export async function SetOnPrototype(doc: Doc, key: string, value: Field) {
- const proto = doc.proto;
+ const proto = Object.getOwnPropertyNames(doc).indexOf("isProto") == -1 ? doc.proto : doc;
+
if (proto) {
proto[key] = value;
}
@@ -160,6 +161,15 @@ export namespace Doc {
return doc;
}
+ // compare whether documents or their protos match
+ export function AreProtosEqual(doc: Doc, other: Doc) {
+ let r = (doc[Id] === other[Id]);
+ let r2 = (doc.proto && doc.proto.Id === other[Id]);
+ let r3 = (other.proto && other.proto.Id === doc[Id]);
+ let r4 = (doc.proto && other.proto && doc.proto[Id] === other.proto[Id]);
+ return r || r2 || r3 || r4 ? true : false;
+ }
+
export function MakeAlias(doc: Doc) {
const alias = new Doc;