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 extends ObjectField { constructor() { super(); const list = new Proxy(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 = ListImpl & T[]; export const List: { new (): List } = ListImpl as any;