aboutsummaryrefslogtreecommitdiff
path: root/src/new_fields/List.ts
diff options
context:
space:
mode:
authoryipstanley <stanley_yip@brown.edu>2019-06-04 14:01:08 -0400
committeryipstanley <stanley_yip@brown.edu>2019-06-04 14:01:08 -0400
commitb33ee6461b4aad420d52600946bee03dcf480e06 (patch)
tree275e6eaa3beb791a6110522efab79b4fa7a6454a /src/new_fields/List.ts
parent1fb7a7bc185c1ba9bbe0f21ad5e16cf19235b2da (diff)
parent7d3ef1c914cc1cc0b6c05b14773a8b83e1b95c96 (diff)
Merge branch 'master' of https://github.com/browngraphicslab/Dash-Web into pdf_impl
Diffstat (limited to 'src/new_fields/List.ts')
-rw-r--r--src/new_fields/List.ts16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/new_fields/List.ts b/src/new_fields/List.ts
index 70e36f911..f1e4c4721 100644
--- a/src/new_fields/List.ts
+++ b/src/new_fields/List.ts
@@ -1,11 +1,12 @@
import { Deserializable, autoObject } from "../client/util/SerializationHelper";
-import { Field, Update, Self, FieldResult, SelfProxy } from "./Doc";
+import { Field } from "./Doc";
import { setter, getter, deleteProperty, updateFunction } from "./util";
import { serializable, alias, list } from "serializr";
import { observable, action } from "mobx";
-import { ObjectField, OnUpdate, Copy, Parent } from "./ObjectField";
+import { ObjectField } from "./ObjectField";
import { RefField } from "./RefField";
import { ProxyField } from "./Proxy";
+import { Self, Update, Parent, OnUpdate, SelfProxy, ToScriptString, Copy } from "./FieldSymbols";
const listHandlers: any = {
/// Mutator methods
@@ -225,7 +226,7 @@ type StoredType<T extends Field> = T extends RefField ? ProxyField<T> : T;
@Deserializable("list")
class ListImpl<T extends Field> extends ObjectField {
- constructor(fields: T[] = []) {
+ constructor(fields?: T[]) {
super();
const list = new Proxy<this>(this, {
set: setter,
@@ -244,7 +245,9 @@ class ListImpl<T extends Field> extends ObjectField {
defineProperty: () => { throw new Error("Currently properties can't be defined on documents using Object.defineProperty"); },
});
this[SelfProxy] = list;
- (list as any).push(...fields);
+ if (fields) {
+ (list as any).push(...fields);
+ }
return list;
}
@@ -284,6 +287,11 @@ class ListImpl<T extends Field> extends ObjectField {
private [Self] = this;
private [SelfProxy]: any;
+
+ [ToScriptString]() {
+ return "invalid";
+ // return `new List([${(this as any).map((field => Field.toScriptString(field))}])`;
+ }
}
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; \ No newline at end of file