diff options
author | ab <abdullah_ahmed@brown.edu> | 2019-05-21 16:37:41 -0400 |
---|---|---|
committer | ab <abdullah_ahmed@brown.edu> | 2019-05-21 16:37:41 -0400 |
commit | 33c29d0e58c1b083e72df7e7fd81bb130f46bd2a (patch) | |
tree | f87bd33e2d98ce2752abec9d189de0de5161fddb /src/new_fields/Doc.ts | |
parent | b3f1e5f60ee4a00522d3e4b0b03495685bde006c (diff) | |
parent | 7e5ba95b02e4ead3ee2b41eca1af0acb72d6f7cd (diff) |
Merge branch 'master' of https://github.com/browngraphicslab/Dash-Web into cont_menu_ui
Diffstat (limited to 'src/new_fields/Doc.ts')
-rw-r--r-- | src/new_fields/Doc.ts | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/src/new_fields/Doc.ts b/src/new_fields/Doc.ts index f4514c33e..b0237d04d 100644 --- a/src/new_fields/Doc.ts +++ b/src/new_fields/Doc.ts @@ -19,12 +19,15 @@ export namespace Field { return field[ToScriptString](); } } - export function IsField(field: any): field is Field { + export function IsField(field: any): field is Field; + export function IsField(field: any, includeUndefined: true): field is Field | undefined; + export function IsField(field: any, includeUndefined: boolean = false): field is Field | undefined { return (typeof field === "string") || (typeof field === "number") || (typeof field === "boolean") || (field instanceof ObjectField) - || (field instanceof RefField); + || (field instanceof RefField) + || (includeUndefined && field === undefined); } } export type Field = number | string | boolean | ObjectField | RefField; @@ -116,7 +119,6 @@ export class Doc extends RefField { } public [HandleUpdate](diff: any) { - console.log(diff); const set = diff.$set; if (set) { for (const key in set) { @@ -149,6 +151,9 @@ export namespace Doc { export function GetT<T extends Field>(doc: Doc, key: string, ctor: ToConstructor<T>, ignoreProto: boolean = false): FieldResult<T> { return Cast(Get(doc, key, ignoreProto), ctor) as FieldResult<T>; } + export function IsPrototype(doc: Doc) { + return GetT(doc, "isPrototype", "boolean", true); + } export async function SetOnPrototype(doc: Doc, key: string, value: Field) { const proto = Object.getOwnPropertyNames(doc).indexOf("isPrototype") === -1 ? doc.proto : doc; @@ -180,11 +185,11 @@ export namespace 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; + let r = (doc === other); + let r2 = (doc.proto === other); + let r3 = (other.proto === doc); + let r4 = (doc.proto === other.proto); + return r || r2 || r3 || r4; } // gets the document's prototype or returns the document if it is a prototype |