diff options
author | bobzel <zzzman@gmail.com> | 2021-03-18 00:08:13 -0400 |
---|---|---|
committer | bobzel <zzzman@gmail.com> | 2021-03-18 00:08:13 -0400 |
commit | 188e1e57860f58e9ebe3536a0e1f7cd84ea0db80 (patch) | |
tree | 72d1824332295c6a58b7b5933125133b19c5c0f3 /src/fields/Doc.ts | |
parent | 6f4f0ffb9f4ab816cf6055c62afc6f79b8e4961f (diff) |
cleaned up link making. Documents don't add to the Undo stack when being created and Initializing is set. Links to text regions automatically update their link line endpoints even if autoMove isn't set. regularized initialization fields to avoid special cases about setting delegate keys without a leading "_"
Diffstat (limited to 'src/fields/Doc.ts')
-rw-r--r-- | src/fields/Doc.ts | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/fields/Doc.ts b/src/fields/Doc.ts index 4f9377aa0..5bc770c15 100644 --- a/src/fields/Doc.ts +++ b/src/fields/Doc.ts @@ -94,6 +94,7 @@ export const AclAddonly = Symbol("AclAddonly"); export const AclEdit = Symbol("AclEdit"); export const AclAdmin = Symbol("AclAdmin"); export const UpdatingFromServer = Symbol("UpdatingFromServer"); +export const Initializing = Symbol("Initializing"); export const ForceServerWrite = Symbol("ForceServerWrite"); export const CachedUpdates = Symbol("Cached updates"); @@ -189,6 +190,7 @@ export class Doc extends RefField { private [UpdatingFromServer]: boolean = false; private [ForceServerWrite]: boolean = false; + public [Initializing]: boolean = false; private [Update] = (diff: any) => { (!this[UpdatingFromServer] || this[ForceServerWrite]) && DocServer.UpdateField(this[Id], diff); @@ -371,7 +373,8 @@ export namespace Doc { * @param fields the fields to project onto the target. Its type signature defines a mapping from some string key * to a potentially undefined field, where each entry in this mapping is optional. */ - export function assign<K extends string>(doc: Doc, fields: Partial<Record<K, Opt<Field>>>, skipUndefineds: boolean = false) { + export function assign<K extends string>(doc: Doc, fields: Partial<Record<K, Opt<Field>>>, skipUndefineds: boolean = false, isInitializing = false) { + isInitializing && (doc[Initializing] = true); for (const key in fields) { if (fields.hasOwnProperty(key)) { const value = fields[key]; @@ -380,6 +383,7 @@ export namespace Doc { } } } + isInitializing && (doc[Initializing] = false); return doc; } @@ -779,10 +783,12 @@ export namespace Doc { export function MakeDelegate(doc: Opt<Doc>, id?: string, title?: string): Opt<Doc> { if (doc) { const delegate = new Doc(id, true); + delegate[Initializing] = true; delegate.proto = doc; delegate.author = Doc.CurrentUserEmail; if (!Doc.IsSystem(doc)) Doc.AddDocToList(doc[DataSym], "aliases", delegate); title && (delegate.title = title); + delegate[Initializing] = false; return delegate; } return undefined; |