diff options
author | Sam Wilkins <abdullah_ahmed@brown.edu> | 2019-04-30 20:41:51 -0400 |
---|---|---|
committer | Sam Wilkins <abdullah_ahmed@brown.edu> | 2019-04-30 20:41:51 -0400 |
commit | ee31019f719b46db57de486e66158e9600515edd (patch) | |
tree | ab197fb9eb1063cb5a91a7ca9e7d8cab2594e7e3 /src/new_fields/Proxy.ts | |
parent | 43ed4e7fd2d6120598733e537a301a8f87379239 (diff) |
all non-list object field [Copy] implemented
Diffstat (limited to 'src/new_fields/Proxy.ts')
-rw-r--r-- | src/new_fields/Proxy.ts | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/new_fields/Proxy.ts b/src/new_fields/Proxy.ts index 56e41cc0f..fd99ae1c0 100644 --- a/src/new_fields/Proxy.ts +++ b/src/new_fields/Proxy.ts @@ -4,20 +4,28 @@ import { primitive, serializable } from "serializr"; import { observable, action } from "mobx"; import { DocServer } from "../client/DocServer"; import { RefField, Id } from "./RefField"; -import { ObjectField } from "./ObjectField"; +import { ObjectField, Copy } from "./ObjectField"; @Deserializable("proxy") export class ProxyField<T extends RefField> extends ObjectField { constructor(); constructor(value: T); - constructor(value?: T) { + constructor(fieldId: string); + constructor(value?: T | string) { super(); - if (value) { + if (typeof value === "string") { + this.fieldId = value; + } else if (value) { this.cache = value; this.fieldId = value[Id]; } } + [Copy]() { + if (this.cache) return new ProxyField<T>(this.cache); + return new ProxyField<T>(this.fieldId); + } + @serializable(primitive()) readonly fieldId: string = ""; |