diff options
-rw-r--r-- | src/new_fields/List.ts | 8 | ||||
-rw-r--r-- | src/new_fields/URLField.ts | 4 |
2 files changed, 8 insertions, 4 deletions
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<T> { type ListUpdate<T> = ListSpliceUpdate<T> | ListIndexUpdate<T>; +type StoredType<T extends Field> = T extends RefField ? ProxyField<T> : T; + @Deserializable("list") class ListImpl<T extends Field> extends ObjectField { constructor(fields: T[] = []) { @@ -216,12 +218,14 @@ class ListImpl<T extends Field> extends ObjectField { } [Copy]() { - return new ListImpl<T>(); + let copiedData = this.__fields.map(f => f instanceof ObjectField ? f[Copy]() : f); + let deepCopy = new ListImpl<T>(copiedData as any); + return deepCopy; } // @serializable(alias("fields", list(autoObject()))) @observable - private ___fields: (T extends RefField ? ProxyField<T> : T)[] = []; + private ___fields: StoredType<T>[] = []; 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); } } |