diff options
Diffstat (limited to 'src/fields/Document.ts')
-rw-r--r-- | src/fields/Document.ts | 49 |
1 files changed, 36 insertions, 13 deletions
diff --git a/src/fields/Document.ts b/src/fields/Document.ts index 2e873439c..d5ff32c6f 100644 --- a/src/fields/Document.ts +++ b/src/fields/Document.ts @@ -2,7 +2,7 @@ import { Key } from "./Key" import { KeyStore } from "./KeyStore"; import { Field, Cast, FieldWaiting, FieldValue, FieldId } from "./Field" import { NumberField } from "./NumberField"; -import { ObservableMap, computed, action } from "mobx"; +import { ObservableMap, computed, action, runInAction } from "mobx"; import { TextField } from "./TextField"; import { ListField } from "./ListField"; import { Server } from "../client/Server"; @@ -201,25 +201,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 @@ -259,6 +271,17 @@ export class Document extends Field { return protos; } + CreateAlias(id?: string): Document { + let alias = new Document(id) + this.GetAsync(KeyStore.Prototype, (f: Field) => { + alias.Set(KeyStore.Prototype, f) + }) + alias.SetNumber(KeyStore.Width, 300) + alias.SetNumber(KeyStore.Height, 300) + + return alias + } + MakeDelegate(id?: string): Document { let delegate = new Document(id); |