diff options
author | Sam Wilkins <samwilkins333@gmail.com> | 2019-07-11 11:17:22 -0400 |
---|---|---|
committer | Sam Wilkins <samwilkins333@gmail.com> | 2019-07-11 11:17:22 -0400 |
commit | 79275265ddc04d8c590fc884eeccf00762c07384 (patch) | |
tree | e24951ace38a37611bb84ac3b51766fbbb95ec61 | |
parent | 1a140c93e9c04b7507d470621e953ddc2a99520b (diff) |
more changes
-rw-r--r-- | src/client/documents/Documents.ts | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts index 961cd3479..cda116570 100644 --- a/src/client/documents/Documents.ts +++ b/src/client/documents/Documents.ts @@ -145,6 +145,8 @@ export namespace Docs { ]); const PrototypeMap: PrototypeMap = new Map(); + const defaultOptions: DocumentOptions = { x: 0, y: 0, width: 300 }; + const Suffix = "Proto"; /** * This function loads or initializes the prototype for each docment type. @@ -165,12 +167,11 @@ export namespace Docs { let actualProtos = await DocServer.GetRefFields(prototypeIds); // update this object to include any default values: DocumentOptions for all prototypes - let defaultOptions: DocumentOptions = { x: 0, y: 0, width: 300 }; prototypeIds.map(id => { let existing = actualProtos[id] as Doc; let type = id.replace(suffix, "") as DocumentType; // get or create prototype of the specified type... - let target = existing || buildPrototype(type, id, defaultOptions); + let target = existing || buildPrototype(type, id); // ...and set it if not undefined (can be undefined only if TemplateMap does not contain // an entry dedicated to the given DocumentType) target && PrototypeMap.set(type, target); @@ -193,14 +194,15 @@ export namespace Docs { * @param options any value specified in the DocumentOptions object likewise * becomes the default value for that key for all delegates */ - function buildPrototype(type: DocumentType, prototypeId: string, defaultOptions: DocumentOptions): Opt<Doc> { + function buildPrototype(type: DocumentType, prototypeId: string): Opt<Doc> { let template = TemplateMap.get(type); if (!template) { return undefined; } let primary = template.primary; let background = template.background; - let options = { ...defaultOptions, ...(template.options || {}), title: prototypeId.toUpperCase().replace("PROTO", "_PROTO") }; + let upper = Suffix.toUpperCase(); + let options = { ...defaultOptions, ...(template.options || {}), title: prototypeId.toUpperCase().replace(upper, `_${upper}`) }; background && (options = { ...options, backgroundLayout: background, }); return Doc.assign(new Doc(prototypeId, true), { ...options, layout: primary, baseLayout: primary }); } |