From 08759e2d5c5e1b9c7455240214f9021eab5ed451 Mon Sep 17 00:00:00 2001 From: Aria Minaei Date: Fri, 2 Jul 2021 20:27:10 +0200 Subject: [PATCH] New: Make SheetObject an IdentityChangeProvider --- theatre/core/src/sheetObjects/SheetObject.ts | 21 +++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/theatre/core/src/sheetObjects/SheetObject.ts b/theatre/core/src/sheetObjects/SheetObject.ts index da23103..244c5e2 100644 --- a/theatre/core/src/sheetObjects/SheetObject.ts +++ b/theatre/core/src/sheetObjects/SheetObject.ts @@ -13,7 +13,12 @@ import type { SerializableValue, } from '@theatre/shared/utils/types' import {valToAtom} from '@theatre/shared/utils/valToAtom' -import type {IDerivation, Pointer} from '@theatre/dataverse' +import type { + IdentityDerivationProvider, + IDerivation, + Pointer, +} from '@theatre/dataverse' + import {Atom, getPointerParts, pointer, prism, val} from '@theatre/dataverse' import type SheetObjectTemplate from './SheetObjectTemplate' import TheatreSheetObject from './TheatreSheetObject' @@ -25,11 +30,11 @@ import TheatreSheetObject from './TheatreSheetObject' // sequenced: SerializableMap // } -export default class SheetObject { +export default class SheetObject implements IdentityDerivationProvider { get type(): 'Theatre_SheetObject' { return 'Theatre_SheetObject' } - + readonly $$isIdentityDerivationProvider: true = true readonly address: SheetObjectAddress readonly publicApi: TheatreSheetObject<$IntentionalAny> private readonly _initialValue = new Atom({}) @@ -130,6 +135,16 @@ export default class SheetObject { return val(pointerDeep(allValuesP as $FixMe, path)) as SerializableMap } + getIdentityDerivation(path: Array): IDerivation { + /** + * @todo perf: Too much indirection here. + */ + return prism(() => { + const allValuesP = val(this.getValues()) + return val(pointerDeep(allValuesP as $FixMe, path)) as SerializableMap + }) + } + /** * Returns values of props that are sequenced. */