From 1c1254431f2b76f9fa5f9b552e2e6ccdd1f45b8b Mon Sep 17 00:00:00 2001 From: Sam Wilkins Date: Tue, 30 Apr 2019 22:46:37 -0400 Subject: copying in theory fully implemented --- src/new_fields/List.ts | 8 ++++++-- src/new_fields/URLField.ts | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/new_fields/List.ts b/src/new_fields/List.ts index 3325302aa..5852e2c30 100644 --- a/src/new_fields/List.ts +++ b/src/new_fields/List.ts @@ -190,6 +190,8 @@ interface ListIndexUpdate { type ListUpdate = ListSpliceUpdate | ListIndexUpdate; +type StoredType = T extends RefField ? ProxyField : T; + @Deserializable("list") class ListImpl extends ObjectField { constructor(fields: T[] = []) { @@ -216,12 +218,14 @@ class ListImpl extends ObjectField { } [Copy]() { - return new ListImpl(); + let copiedData = this.__fields.map(f => f instanceof ObjectField ? f[Copy]() : f); + let deepCopy = new ListImpl(copiedData as any); + return deepCopy; } // @serializable(alias("fields", list(autoObject()))) @observable - private ___fields: (T extends RefField ? ProxyField : T)[] = []; + private ___fields: StoredType[] = []; private [Update] = (diff: any) => { // console.log(diff); diff --git a/src/new_fields/URLField.ts b/src/new_fields/URLField.ts index d7120a5d2..d00a95a16 100644 --- a/src/new_fields/URLField.ts +++ b/src/new_fields/URLField.ts @@ -22,8 +22,8 @@ export class URLField extends ObjectField { this.url = url; } - [Copy]() { - return new URLField(this.url); + [Copy](): this { + return new (this.constructor as any)(this.url); } } -- cgit v1.2.3-70-g09d2