diff options
author | bobzel <zzzman@gmail.com> | 2020-02-07 15:08:28 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-07 15:08:28 -0500 |
commit | f3374e5db522b47529ce52ac57e0a9c498666ff7 (patch) | |
tree | 400bc2038464c8a57c8f09e0c57369a837e025df /src/new_fields/Doc.ts | |
parent | 688f54be8be328d733e05b0781aa8908305e14fa (diff) | |
parent | d310058e80f0896e2724f8723d5b95e1077296c1 (diff) |
Merge pull request #335 from browngraphicslab/fixinglayoutsyms
Fixinglayoutsyms
Diffstat (limited to 'src/new_fields/Doc.ts')
-rw-r--r-- | src/new_fields/Doc.ts | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/src/new_fields/Doc.ts b/src/new_fields/Doc.ts index 529634990..3abd6aaa4 100644 --- a/src/new_fields/Doc.ts +++ b/src/new_fields/Doc.ts @@ -1,4 +1,4 @@ -import { observable, ObservableMap, runInAction, action } from "mobx"; +import { observable, ObservableMap, runInAction, action, computed } from "mobx"; import { alias, map, serializable } from "serializr"; import { DocServer } from "../client/DocServer"; import { DocumentType } from "../client/documents/DocumentTypes"; @@ -90,6 +90,7 @@ export function DocListCast(field: FieldResult): Doc[] { export const WidthSym = Symbol("Width"); export const HeightSym = Symbol("Height"); export const DataSym = Symbol("Data"); +export const LayoutSym = Symbol("Layout"); export const UpdatingFromServer = Symbol("UpdatingFromServer"); const CachedUpdates = Symbol("Cached updates"); @@ -111,8 +112,11 @@ export class Doc extends RefField { get: getter, // getPrototypeOf: (target) => Cast(target[SelfProxy].proto, Doc) || null, // TODO this might be able to replace the proto logic in getter has: (target, key) => key in target.__fields, - ownKeys: target => Object.keys(target.__fields), + ownKeys: target => Object.keys(target.__allfields), getOwnPropertyDescriptor: (target, prop) => { + if (prop.toString() === "__LAYOUT__") { + return Reflect.getOwnPropertyDescriptor(target, prop); + } if (prop in target.__fields) { return { configurable: true,//TODO Should configurable be true? @@ -139,6 +143,12 @@ export class Doc extends RefField { private get __fields() { return this.___fields; } + private get __allfields() { + let obj = this.___fields; + obj.__LAYOUT__ = this.__LAYOUT__; + return obj; + } + private set __fields(value) { this.___fields = value; @@ -168,6 +178,15 @@ export class Doc extends RefField { public [WidthSym] = () => NumCast(this[SelfProxy]._width); public [HeightSym] = () => NumCast(this[SelfProxy]._height); public get [DataSym]() { return Cast(this[SelfProxy].resolvedDataDoc, Doc, null) || this[SelfProxy]; } + @computed public get __LAYOUT__() { + const layoutKey = StrCast(this[SelfProxy].layoutKey); + const resolvedLayout = Cast(this[SelfProxy][layoutKey], Doc); + if (resolvedLayout instanceof Doc) { + let layout = (resolvedLayout.layout as string).split("'")[1]; + return this[SelfProxy][layout + "-layout[" + resolvedLayout[Id] + "]"]; + } + return undefined; + } [ToScriptString]() { return "invalid"; |