aboutsummaryrefslogtreecommitdiff
path: root/src/new_fields/List.ts
diff options
context:
space:
mode:
authorTyler Schicke <tyler_schicke@brown.edu>2019-04-19 23:13:17 -0400
committerTyler Schicke <tyler_schicke@brown.edu>2019-04-19 23:13:17 -0400
commite678ac7f21e0c44eaa8ad88577093cdb313e21bb (patch)
tree9fb0f73365ae427ebbc5c48ca1887394e16fe5bd /src/new_fields/List.ts
parent3e96161afe4f48afa6abd1b2158b5a1c4fe85a32 (diff)
Deleted more old fields and split new stuff into multiple files
Diffstat (limited to 'src/new_fields/List.ts')
-rw-r--r--src/new_fields/List.ts35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/new_fields/List.ts b/src/new_fields/List.ts
new file mode 100644
index 000000000..a1a623f83
--- /dev/null
+++ b/src/new_fields/List.ts
@@ -0,0 +1,35 @@
+import { Deserializable, autoObject } from "../client/util/SerializationHelper";
+import { Field, ObjectField, Update, OnUpdate, Self } from "./Doc";
+import { setter, getter } from "./util";
+import { serializable, alias, list } from "serializr";
+import { observable } from "mobx";
+
+@Deserializable("list")
+class ListImpl<T extends Field> extends ObjectField {
+ constructor() {
+ super();
+ const list = new Proxy<this>(this, {
+ set: function (a, b, c, d) { return setter(a, b, c, d); },
+ get: getter,
+ deleteProperty: () => { throw new Error("Currently properties can't be deleted from documents, assign to undefined instead"); },
+ defineProperty: () => { throw new Error("Currently properties can't be defined on documents using Object.defineProperty"); },
+ });
+ return list;
+ }
+
+ [key: number]: T | null | undefined;
+
+ @serializable(alias("fields", list(autoObject())))
+ @observable
+ private __fields: (T | null | undefined)[] = [];
+
+ private [Update] = (diff: any) => {
+ console.log(diff);
+ const update = this[OnUpdate];
+ update && update(diff);
+ }
+
+ private [Self] = this;
+}
+export type List<T extends Field> = ListImpl<T> & T[];
+export const List: { new <T extends Field>(): List<T> } = ListImpl as any; \ No newline at end of file