aboutsummaryrefslogtreecommitdiff
path: root/src/new_fields/util.ts
diff options
context:
space:
mode:
authorMohammad Amoush <47069173+mamoush34@users.noreply.github.com>2020-02-08 17:03:12 -0500
committerMohammad Amoush <47069173+mamoush34@users.noreply.github.com>2020-02-08 17:03:12 -0500
commitf9855e8d1ec83405ae3cc7d0113b46de63fc0848 (patch)
treebf4be61a021e59b771c1cd5958fd9fd43cac8693 /src/new_fields/util.ts
parent87f5f043388b591c52e96a795fa461a79770550d (diff)
parent1b046f76cf39f1f6cb1875aa84b45db74b6d994e (diff)
Merge branch 'master' of https://github.com/browngraphicslab/Dash-Web into webcam_mohammad
Diffstat (limited to 'src/new_fields/util.ts')
-rw-r--r--src/new_fields/util.ts38
1 files changed, 32 insertions, 6 deletions
diff --git a/src/new_fields/util.ts b/src/new_fields/util.ts
index 4147be278..ebc0a1272 100644
--- a/src/new_fields/util.ts
+++ b/src/new_fields/util.ts
@@ -1,19 +1,20 @@
import { UndoManager } from "../client/util/UndoManager";
-import { Doc, Field, FieldResult, UpdatingFromServer } from "./Doc";
+import { Doc, Field, FieldResult, UpdatingFromServer, LayoutSym } 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");
}
export function TraceMobx() {
- //trace();
+ // trace();
}
export interface GetterResult {
@@ -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,35 @@ 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", "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.startsWith("_") || layoutProps.includes(prop))) {
+ if (!prop.startsWith("_")) {
+ console.log(prop + " is deprecated - switch to _" + prop);
+ prop = "_" + prop;
+ }
+ if (target.__LAYOUT__) {
+ target.__LAYOUT__[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 (prop === LayoutSym) {
+ return target.__LAYOUT__;
+ }
+ if (typeof prop === "string" && prop !== "__id" && prop !== "__fields" && (prop.startsWith("_") || layoutProps.includes(prop))) {
+ if (!prop.startsWith("_")) {
+ console.log(prop + " is deprecated - switch to _" + prop);
+ prop = "_" + prop;
+ }
+ if (target.__LAYOUT__) return target.__LAYOUT__[prop];
+ }
if (prop === "then") {//If we're being awaited
return undefined;
}