diff options
author | bobzel <zzzman@gmail.com> | 2023-01-02 15:05:51 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-02 15:05:51 -0500 |
commit | 9211251c8a632ef84198253a0d3086df11af9ead (patch) | |
tree | 378330aeaecdd68e291dfa0b68c339dfa1c233da /src/fields/ScriptField.ts | |
parent | 4c0de84cf9a3d5be2f5058d514c8ca58e2004a4b (diff) | |
parent | da9aef9e4cda036264801191361c1ecfacd9ba0b (diff) |
Merge pull request #157 from brown-dash/robustness
cleaning up ACLs for performance and clarity
Diffstat (limited to 'src/fields/ScriptField.ts')
-rw-r--r-- | src/fields/ScriptField.ts | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/src/fields/ScriptField.ts b/src/fields/ScriptField.ts index 4896c027d..b23732b45 100644 --- a/src/fields/ScriptField.ts +++ b/src/fields/ScriptField.ts @@ -6,11 +6,10 @@ import { scriptingGlobal, ScriptingGlobals } from '../client/util/ScriptingGloba import { autoObject, Deserializable } from '../client/util/SerializationHelper'; import { numberRange } from '../Utils'; import { Doc, Field, Opt } from './Doc'; -import { Copy, Id, ToScriptString, ToString } from './FieldSymbols'; +import { Copy, Id, ToScriptString, ToString, ToValue } from './FieldSymbols'; import { List } from './List'; import { ObjectField } from './ObjectField'; import { Cast, StrCast } from './Types'; -import { Plugins } from './util'; function optional(propSchema: PropSchema) { return custom( @@ -175,6 +174,9 @@ export class ComputedField extends ScriptField { value = computedFn((doc: Doc) => this._valueOutsideReaction(doc)); _valueOutsideReaction = (doc: Doc) => (this._lastComputedResult = this.script.run({ this: doc, self: Cast(doc.rootDocument, Doc, null) || doc, _last_: this._lastComputedResult, _readOnly_: true }, console.log).result); + [ToValue](doc: Doc) { + return ComputedField.toValue(doc, this); + } [Copy](): ObjectField { return new ComputedField(this.script, this.setterscript, this.rawscript); } @@ -239,12 +241,10 @@ export namespace ComputedField { } } - export function initPlugin() { - Plugins.addGetterPlugin((doc, _, value) => { - if (useComputed && value instanceof ComputedField) { - return { value: value._valueOutsideReaction(doc), shouldReturn: true }; - } - }); + export function toValue(doc: any, value: any) { + if (useComputed) { + return { value: value._valueOutsideReaction(doc) }; + } } } |