diff options
author | tschicke-brown <tyler_schicke@brown.edu> | 2019-06-24 13:57:02 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-24 13:57:02 -0400 |
commit | addf0e443f64951a437701f0d5a087c1d5968faf (patch) | |
tree | a97d85738f3173896aeffa04a22368b70b9dcdc3 /src/new_fields/util.ts | |
parent | c9f77d5aab98e6e7865cdcad957d5c937631775d (diff) | |
parent | d01039b10f0ebd328224c0b1a190b0f884a7c727 (diff) |
Merge pull request #167 from browngraphicslab/schema_fixes
Schema and scripting fixes
Diffstat (limited to 'src/new_fields/util.ts')
-rw-r--r-- | src/new_fields/util.ts | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/new_fields/util.ts b/src/new_fields/util.ts index cc937c567..cadd8f8d0 100644 --- a/src/new_fields/util.ts +++ b/src/new_fields/util.ts @@ -7,7 +7,7 @@ import { RefField } from "./RefField"; import { ObjectField } from "./ObjectField"; import { action } from "mobx"; import { Parent, OnUpdate, Update, Id, SelfProxy, Self } from "./FieldSymbols"; -import { ComputedField } from "../fields/ScriptField"; +import { ComputedField } from "./ScriptField"; function _readOnlySetter(): never { throw new Error("Documents can't be modified in read-only mode"); @@ -21,6 +21,7 @@ const _setterImpl = action(function (target: any, prop: string | symbol | number target[prop] = value; return true; } + value = value[SelfProxy] || value; const curValue = target.__fields[prop]; if (curValue === value || (curValue instanceof ProxyField && value instanceof RefField && curValue.fieldId === value[Id])) { // TODO This kind of checks correctly in the case that curValue is a ProxyField and value is a RefField, but technically @@ -31,11 +32,10 @@ const _setterImpl = action(function (target: any, prop: string | symbol | number value = new ProxyField(value); } if (value instanceof ObjectField) { - //TODO Instead of target, maybe use target[Self] - if (value[Parent] && value[Parent] !== target) { + if (value[Parent] && value[Parent] !== receiver) { throw new Error("Can't put the same object in multiple documents at the same time"); } - value[Parent] = target; + value[Parent] = receiver; value[OnUpdate] = updateFunction(target, prop, value, receiver); } if (curValue instanceof ObjectField) { |