diff options
author | Stanley Yip <stanley_yip@brown.edu> | 2020-01-30 18:45:55 -0500 |
---|---|---|
committer | Stanley Yip <stanley_yip@brown.edu> | 2020-01-30 18:45:55 -0500 |
commit | 76b99cf70c36ca8a691010c86f5f444dd30eb004 (patch) | |
tree | 396d7328d46d66dc83afc7f2941d410538243bf5 /src/new_fields/util.ts | |
parent | 17dcf7e4d8c2f038dc3a6168b1ff6b8d3cb15536 (diff) | |
parent | d7a076ca7315a892b6a43b0e7454abf470f48455 (diff) |
some bugfixes
Diffstat (limited to 'src/new_fields/util.ts')
-rw-r--r-- | src/new_fields/util.ts | 37 |
1 files changed, 33 insertions, 4 deletions
diff --git a/src/new_fields/util.ts b/src/new_fields/util.ts index 4147be278..2cedda7a6 100644 --- a/src/new_fields/util.ts +++ b/src/new_fields/util.ts @@ -1,12 +1,13 @@ import { UndoManager } from "../client/util/UndoManager"; import { Doc, Field, FieldResult, UpdatingFromServer } from "./Doc"; import { SerializationHelper } from "../client/util/SerializationHelper"; -import { ProxyField } from "./Proxy"; +import { ProxyField, PrefetchProxy } from "./Proxy"; import { RefField } from "./RefField"; import { ObjectField } from "./ObjectField"; import { action, trace } from "mobx"; import { Parent, OnUpdate, Update, Id, SelfProxy, Self } from "./FieldSymbols"; import { DocServer } from "../client/DocServer"; +import { props } from "bluebird"; function _readOnlySetter(): never { throw new Error("Documents can't be modified in read-only mode"); @@ -35,6 +36,7 @@ const _setterImpl = action(function (target: any, prop: string | symbol | number target[prop] = value; return true; } + if (typeof prop === "symbol") { target[prop] = value; return true; @@ -52,7 +54,7 @@ const _setterImpl = action(function (target: any, prop: string | symbol | number value = new ProxyField(value); } if (value instanceof ObjectField) { - if (value[Parent] && value[Parent] !== receiver) { + if (value[Parent] && value[Parent] !== receiver && !(value instanceof PrefetchProxy)) { throw new Error("Can't put the same object in multiple documents at the same time"); } value[Parent] = receiver; @@ -98,11 +100,38 @@ export function makeEditable() { _setter = _setterImpl; } -export function setter(target: any, prop: string | symbol | number, value: any, receiver: any): boolean { +let layoutProps = ["panX", "panY", "width", "height", "nativeWidth", "nativeHeight", "fitWidth", "fitToBox", + "LODdisable", "dropAction", "chromeStatus", "viewType", "gridGap", "xMargin", "yMargin", "autoHeight"]; +export function setter(target: any, in_prop: string | symbol | number, value: any, receiver: any): boolean { + let prop = in_prop; + if (typeof prop === "string" && prop !== "__id" && prop !== "__fields" && + ((prop as string).startsWith("_") || layoutProps.includes(prop))) { + if (!prop.startsWith("_")) { + console.log(prop + " is deprecated - switch to _" + prop); + prop = "_" + prop; + } + const resolvedLayout = getFieldImpl(target, getFieldImpl(target, "layoutKey", receiver), receiver); + if (resolvedLayout instanceof Doc) { + resolvedLayout[prop] = value; + return true; + } + } return _setter(target, prop, value, receiver); } -export function getter(target: any, prop: string | symbol | number, receiver: any): any { +export function getter(target: any, in_prop: string | symbol | number, receiver: any): any { + let prop = in_prop; + if (typeof prop === "string" && prop !== "__id" && prop !== "__fields" && + ((prop as string).startsWith("_") || layoutProps.includes(prop))) { + if (!prop.startsWith("_")) { + console.log(prop + " is deprecated - switch to _" + prop); + prop = "_" + prop; + } + const resolvedLayout = getFieldImpl(target, getFieldImpl(target, "layoutKey", receiver), receiver); + if (resolvedLayout instanceof Doc) { + return resolvedLayout[prop]; + } + } if (prop === "then") {//If we're being awaited return undefined; } |