diff options
author | yipstanley <stanley_yip@brown.edu> | 2019-02-23 19:15:03 -0500 |
---|---|---|
committer | yipstanley <stanley_yip@brown.edu> | 2019-02-23 19:15:03 -0500 |
commit | 8d2dc530854517830dc55d7f7a0f02828bd7f8f6 (patch) | |
tree | 82a38d9fda5b67ba7491d94e45b48d2c8ae64145 /src | |
parent | d9d55e422826da1fe87aa7973c92e54bc0c99f02 (diff) |
set on prototype implemented
Diffstat (limited to 'src')
-rw-r--r-- | src/fields/Document.ts | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/src/fields/Document.ts b/src/fields/Document.ts index 0d7d357a0..823991759 100644 --- a/src/fields/Document.ts +++ b/src/fields/Document.ts @@ -140,25 +140,37 @@ export class Document extends Field { } @action - Set(key: Key, field: Field | undefined): void { + SetOnPrototype(key: Key, field: Field | undefined): void { + this.GetAsync(KeyStore.Prototype, (f: Field) => { + (f as Document).Set(key, field) + }) + } + + @action + Set(key: Key, field: Field | undefined, setOnPrototype = false): void { let old = this.fields.get(key.Id); let oldField = old ? old.field : undefined; - if (field) { - this.fields.set(key.Id, { key, field }); - this._proxies.set(key.Id, field.Id) - // Server.AddDocumentField(this, key, field); - } else { - this.fields.delete(key.Id); - this._proxies.delete(key.Id) - // Server.DeleteDocumentField(this, key); + if (setOnPrototype) { + this.SetOnPrototype(key, field) + } + else { + if (field) { + this.fields.set(key.Id, { key, field }); + this._proxies.set(key.Id, field.Id) + // Server.AddDocumentField(this, key, field); + } else { + this.fields.delete(key.Id); + this._proxies.delete(key.Id) + // Server.DeleteDocumentField(this, key); + } + Server.UpdateField(this); } if (oldField || field) { UndoManager.AddEvent({ - undo: () => this.Set(key, oldField), - redo: () => this.Set(key, field) + undo: () => this.Set(key, oldField, setOnPrototype), + redo: () => this.Set(key, field, setOnPrototype) }) } - Server.UpdateField(this); } @action |