diff options
author | geireann <60007097+geireann@users.noreply.github.com> | 2020-08-24 18:47:33 +0800 |
---|---|---|
committer | geireann <60007097+geireann@users.noreply.github.com> | 2020-08-24 18:47:33 +0800 |
commit | 31fac41cb8a3bd19b02dddc116b11c962f3339d3 (patch) | |
tree | 7d3b0bcf04318d479158915f5ee7fc8a30ef580c /src/fields/List.ts | |
parent | 78efe1087488265da4ea37373a2a9a22a7f8cf10 (diff) | |
parent | a9e08e0504e8002bc5d991b6a13777577ddd8f9f (diff) |
Merge branch 'master' into presentation_updates
Diffstat (limited to 'src/fields/List.ts')
-rw-r--r-- | src/fields/List.ts | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/src/fields/List.ts b/src/fields/List.ts index a9da75abb..3601f282b 100644 --- a/src/fields/List.ts +++ b/src/fields/List.ts @@ -1,14 +1,16 @@ -import { Deserializable, autoObject, afterDocDeserialize } from "../client/util/SerializationHelper"; +import { action, observable, runInAction } from "mobx"; +import { alias, list, serializable } from "serializr"; +import { DocServer } from "../client/DocServer"; +import { Scripting } from "../client/util/Scripting"; +import { afterDocDeserialize, autoObject, Deserializable } from "../client/util/SerializationHelper"; import { Field } from "./Doc"; -import { setter, getter, deleteProperty, updateFunction } from "./util"; -import { serializable, alias, list } from "serializr"; -import { observable, action, runInAction } from "mobx"; +import { Copy, OnUpdate, Parent, Self, SelfProxy, ToScriptString, ToString, Update } from "./FieldSymbols"; import { ObjectField } from "./ObjectField"; -import { RefField } from "./RefField"; import { ProxyField } from "./Proxy"; -import { Self, Update, Parent, OnUpdate, SelfProxy, ToScriptString, ToString, Copy, Id } from "./FieldSymbols"; -import { Scripting } from "../client/util/Scripting"; -import { DocServer } from "../client/DocServer"; +import { RefField } from "./RefField"; +import { listSpec } from "./Schema"; +import { Cast } from "./Types"; +import { deleteProperty, getter, setter, updateFunction } from "./util"; const listHandlers: any = { /// Mutator methods @@ -328,4 +330,9 @@ class ListImpl<T extends Field> extends ObjectField { export type List<T extends Field> = ListImpl<T> & (T | (T extends RefField ? Promise<T> : never))[]; export const List: { new <T extends Field>(fields?: T[]): List<T> } = ListImpl as any; -Scripting.addGlobal("List", List);
\ No newline at end of file +Scripting.addGlobal("List", List); +Scripting.addGlobal(function compareLists(l1: any, l2: any) { + const L1 = Cast(l1, listSpec("string"), []); + const L2 = Cast(l2, listSpec("string"), []); + return !L1 && !L2 ? true : L1 && L2 && L1.length === L2.length && L2.reduce((p, v) => p && L1.includes(v), true); +}, "compare two lists");
\ No newline at end of file |