From 12b3f477bc5f25775ba482fe157c9b915fe707cc Mon Sep 17 00:00:00 2001 From: Aria Minaei Date: Thu, 1 Dec 2022 14:20:50 +0100 Subject: [PATCH] Unify Derivation and Prism (1/n) --- packages/dataverse/src/Atom.ts | 14 ++++---- packages/dataverse/src/Box.ts | 6 ++-- .../dataverse/src/derivations/IDerivation.ts | 6 ++-- .../src/derivations/iterateAndCountTicks.ts | 6 ++-- .../dataverse/src/derivations/iterateOver.ts | 6 ++-- .../derivations/prism/discoveryMechanism.ts | 8 ++--- .../dataverse/src/derivations/prism/prism.ts | 33 ++++++++----------- packages/dataverse/src/index.ts | 2 +- packages/react/src/index.ts | 12 +++---- .../src/projects/initialiseProjectState.ts | 2 +- theatre/core/src/sequences/Sequence.ts | 20 +++++------ .../interpolationTripleAtPosition.ts | 16 ++++----- .../AudioPlaybackController.ts | 4 +-- .../DefaultPlaybackController.ts | 6 ++-- theatre/core/src/sheetObjects/SheetObject.ts | 10 +++--- .../src/sheetObjects/SheetObjectTemplate.ts | 10 +++--- .../src/sheetObjects/TheatreSheetObject.ts | 6 ++-- theatre/studio/src/TheatreStudio.ts | 4 +-- .../studio/src/UIRoot/useKeyboardShortcuts.ts | 4 +-- .../SingleRowPropEditor.tsx | 4 +-- .../AggregatedKeyframeTrack.tsx | 4 +-- .../DopeSheet/selections.ts | 4 +-- .../FrameStampPositionProvider.tsx | 6 ++-- .../SequenceEditorPanel/layout/layout.ts | 4 +-- .../whatPropIsHighlighted.ts | 4 +-- .../useEditingToolsForSimpleProp.tsx | 8 ++--- .../uiComponents/Popover/TooltipContext.tsx | 4 +-- theatre/studio/src/utils/derive-utils.tsx | 12 +++---- 28 files changed, 109 insertions(+), 116 deletions(-) diff --git a/packages/dataverse/src/Atom.ts b/packages/dataverse/src/Atom.ts index 44fedf5..172c39a 100644 --- a/packages/dataverse/src/Atom.ts +++ b/packages/dataverse/src/Atom.ts @@ -1,7 +1,7 @@ import get from 'lodash-es/get' import isPlainObject from 'lodash-es/isPlainObject' import last from 'lodash-es/last' -import type {IDerivation} from './derivations/IDerivation' +import type {Prism} from './derivations/IDerivation' import {isDerivation} from './derivations/IDerivation' import type {Pointer, PointerType} from './pointer' import {isPointer} from './pointer' @@ -34,7 +34,7 @@ export interface IdentityDerivationProvider { * * @param path - The path to create the derivation at. */ - getIdentityDerivation(path: Array): IDerivation + getIdentityDerivation(path: Array): Prism } const getTypeOfValue = (v: unknown): ValueTypes => { @@ -246,7 +246,7 @@ export default class Atom * * @param path - The path to create the derivation at. */ - getIdentityDerivation(path: Array): IDerivation { + getIdentityDerivation(path: Array): Prism { const subscribe = (listener: (val: unknown) => void) => this._onPathValueChange(path, listener) @@ -258,7 +258,7 @@ export default class Atom } } -const identityDerivationWeakMap = new WeakMap<{}, IDerivation>() +const identityDerivationWeakMap = new WeakMap<{}, Prism>() /** * Returns a derivation of the value at the provided pointer. Derivations are @@ -268,7 +268,7 @@ const identityDerivationWeakMap = new WeakMap<{}, IDerivation>() */ export const valueDerivation =

>( pointer: P, -): IDerivation

? T : void> => { +): Prism

? T : void> => { const meta = getPointerMeta(pointer) let derivation = identityDerivationWeakMap.get(meta) @@ -309,14 +309,14 @@ function isIdentityDerivationProvider( export const val = < P extends | PointerType<$IntentionalAny> - | IDerivation<$IntentionalAny> + | Prism<$IntentionalAny> | undefined | null, >( input: P, ): P extends PointerType ? T - : P extends IDerivation + : P extends Prism ? T : P extends undefined | null ? P diff --git a/packages/dataverse/src/Box.ts b/packages/dataverse/src/Box.ts index ab99170..7cacf25 100644 --- a/packages/dataverse/src/Box.ts +++ b/packages/dataverse/src/Box.ts @@ -1,4 +1,4 @@ -import type {IDerivation} from './derivations/IDerivation' +import type {Prism} from './derivations/IDerivation' import prism from './derivations/prism/prism' import Emitter from './utils/Emitter' @@ -27,7 +27,7 @@ export interface IBox { /** * Creates a derivation of the Box that you can use to track changes to it. */ - derivation: IDerivation + derivation: Prism } /** @@ -39,7 +39,7 @@ export interface IBox { * reference even if the objects are structurally equal. */ export default class Box implements IBox { - private _publicDerivation: IDerivation + private _publicDerivation: Prism private _emitter = new Emitter() /** diff --git a/packages/dataverse/src/derivations/IDerivation.ts b/packages/dataverse/src/derivations/IDerivation.ts index c5ddaf5..202110d 100644 --- a/packages/dataverse/src/derivations/IDerivation.ts +++ b/packages/dataverse/src/derivations/IDerivation.ts @@ -1,12 +1,12 @@ import type Ticker from '../Ticker' import type {$IntentionalAny, VoidFn} from '../types' -type IDependent = (msgComingFrom: IDerivation<$IntentionalAny>) => void +type IDependent = (msgComingFrom: Prism<$IntentionalAny>) => void /** * Common interface for derivations. */ -export interface IDerivation { +export interface Prism { /** * Whether the object is a derivation. */ @@ -63,6 +63,6 @@ export interface IDerivation { /** * Returns whether `d` is a derivation. */ -export function isDerivation(d: any): d is IDerivation { +export function isDerivation(d: any): d is Prism { return d && d.isDerivation && d.isDerivation === true } diff --git a/packages/dataverse/src/derivations/iterateAndCountTicks.ts b/packages/dataverse/src/derivations/iterateAndCountTicks.ts index 6e8e54c..586e558 100644 --- a/packages/dataverse/src/derivations/iterateAndCountTicks.ts +++ b/packages/dataverse/src/derivations/iterateAndCountTicks.ts @@ -1,15 +1,15 @@ import {valueDerivation} from '../Atom' import type {Pointer} from '../pointer' import {isPointer} from '../pointer' -import type {IDerivation} from './IDerivation' +import type {Prism} from './IDerivation' import {isDerivation} from './IDerivation' export default function* iterateAndCountTicks( - pointerOrDerivation: IDerivation | Pointer, + pointerOrDerivation: Prism | Pointer, ): Generator<{value: V; ticks: number}, void, void> { let d if (isPointer(pointerOrDerivation)) { - d = valueDerivation(pointerOrDerivation) as IDerivation + d = valueDerivation(pointerOrDerivation) as Prism } else if (isDerivation(pointerOrDerivation)) { d = pointerOrDerivation } else { diff --git a/packages/dataverse/src/derivations/iterateOver.ts b/packages/dataverse/src/derivations/iterateOver.ts index 73681ec..1071d04 100644 --- a/packages/dataverse/src/derivations/iterateOver.ts +++ b/packages/dataverse/src/derivations/iterateOver.ts @@ -2,15 +2,15 @@ import {valueDerivation} from '../Atom' import type {Pointer} from '../pointer' import {isPointer} from '../pointer' import Ticker from '../Ticker' -import type {IDerivation} from './IDerivation' +import type {Prism} from './IDerivation' import {isDerivation} from './IDerivation' export default function* iterateOver( - pointerOrDerivation: IDerivation | Pointer, + pointerOrDerivation: Prism | Pointer, ): Generator { let d if (isPointer(pointerOrDerivation)) { - d = valueDerivation(pointerOrDerivation) as IDerivation + d = valueDerivation(pointerOrDerivation) as Prism } else if (isDerivation(pointerOrDerivation)) { d = pointerOrDerivation } else { diff --git a/packages/dataverse/src/derivations/prism/discoveryMechanism.ts b/packages/dataverse/src/derivations/prism/discoveryMechanism.ts index a3849af..2b56320 100644 --- a/packages/dataverse/src/derivations/prism/discoveryMechanism.ts +++ b/packages/dataverse/src/derivations/prism/discoveryMechanism.ts @@ -1,6 +1,6 @@ import type {$IntentionalAny} from '../../types' import Stack from '../../utils/Stack' -import type {IDerivation} from '../IDerivation' +import type {Prism} from '../IDerivation' function createMechanism() { const noop = () => {} @@ -8,7 +8,7 @@ function createMechanism() { const stack = new Stack() const noopCollector: Collector = noop - type Collector = (d: IDerivation<$IntentionalAny>) => void + type Collector = (d: Prism<$IntentionalAny>) => void const pushCollector = (collector: Collector): void => { stack.push(collector) @@ -36,7 +36,7 @@ function createMechanism() { } } - const reportResolutionStart = (d: IDerivation<$IntentionalAny>) => { + const reportResolutionStart = (d: Prism<$IntentionalAny>) => { const possibleCollector = stack.peek() if (possibleCollector) { possibleCollector(d) @@ -45,7 +45,7 @@ function createMechanism() { stack.push(noopCollector) } - const reportResolutionEnd = (_d: IDerivation<$IntentionalAny>) => { + const reportResolutionEnd = (_d: Prism<$IntentionalAny>) => { stack.pop() } diff --git a/packages/dataverse/src/derivations/prism/prism.ts b/packages/dataverse/src/derivations/prism/prism.ts index ef9012d..8f3337a 100644 --- a/packages/dataverse/src/derivations/prism/prism.ts +++ b/packages/dataverse/src/derivations/prism/prism.ts @@ -1,7 +1,7 @@ import type Ticker from '../../Ticker' import type {$IntentionalAny, VoidFn} from '../../types' import Stack from '../../utils/Stack' -import type {IDerivation} from '../IDerivation' +import type {Prism} from '../IDerivation' import {isDerivation} from '../IDerivation' import { startIgnoringDependencies, @@ -12,15 +12,14 @@ import { reportResolutionEnd, } from './discoveryMechanism' -type IDependent = (msgComingFrom: IDerivation<$IntentionalAny>) => void +type IDependent = (msgComingFrom: Prism<$IntentionalAny>) => void const voidFn = () => {} class HotHandle { private _didMarkDependentsAsStale: boolean = false private _isFresh: boolean = false - protected _cacheOfDendencyValues: Map, unknown> = - new Map() + protected _cacheOfDendencyValues: Map, unknown> = new Map() /** * @internal @@ -30,9 +29,9 @@ class HotHandle { /** * @internal */ - protected _dependencies: Set> = new Set() + protected _dependencies: Set> = new Set() - protected _possiblyStaleDeps = new Set>() + protected _possiblyStaleDeps = new Set>() private _scope: HotScope = new HotScope( this as $IntentionalAny as HotHandle, @@ -112,10 +111,10 @@ class HotHandle { } } - const newDeps: Set> = new Set() + const newDeps: Set> = new Set() this._cacheOfDendencyValues.clear() - const collector = (observedDep: IDerivation): void => { + const collector = (observedDep: Prism): void => { newDeps.add(observedDep) this._addDependency(observedDep) } @@ -161,9 +160,7 @@ class HotHandle { this._markAsStale() } - protected _reactToDependencyGoingStale = ( - which: IDerivation<$IntentionalAny>, - ) => { + protected _reactToDependencyGoingStale = (which: Prism<$IntentionalAny>) => { this._possiblyStaleDeps.add(which) this._markAsStale() @@ -183,7 +180,7 @@ class HotHandle { /** * @internal */ - protected _addDependency(d: IDerivation<$IntentionalAny>) { + protected _addDependency(d: Prism<$IntentionalAny>) { if (this._dependencies.has(d)) return this._dependencies.add(d) d._addDependent(this._reactToDependencyGoingStale) @@ -192,7 +189,7 @@ class HotHandle { /** * @internal */ - protected _removeDependency(d: IDerivation<$IntentionalAny>) { + protected _removeDependency(d: Prism<$IntentionalAny>) { if (!this._dependencies.has(d)) return this._dependencies.delete(d) d._removeDependent(this._reactToDependencyGoingStale) @@ -201,7 +198,7 @@ class HotHandle { const emptyObject = {} -class PrismDerivation implements IDerivation { +class PrismDerivation implements Prism { /** * Whether the object is a derivation. */ @@ -703,11 +700,9 @@ function inPrism(): boolean { return !!hookScopeStack.peek() } -const possibleDerivationToValue = < - P extends IDerivation<$IntentionalAny> | unknown, ->( +const possibleDerivationToValue =

| unknown>( input: P, -): P extends IDerivation ? T : P => { +): P extends Prism ? T : P => { if (isDerivation(input)) { return input.getValue() as $IntentionalAny } else { @@ -728,7 +723,7 @@ function source( } type IPrismFn = { - (fn: () => T): IDerivation + (fn: () => T): Prism ref: typeof ref effect: typeof effect memo: typeof memo diff --git a/packages/dataverse/src/index.ts b/packages/dataverse/src/index.ts index 5bbb2bb..7f3d15c 100644 --- a/packages/dataverse/src/index.ts +++ b/packages/dataverse/src/index.ts @@ -9,7 +9,7 @@ export {default as Atom, val, valueDerivation} from './Atom' export {default as Box} from './Box' export type {IBox} from './Box' export {isDerivation} from './derivations/IDerivation' -export type {IDerivation} from './derivations/IDerivation' +export type {Prism} from './derivations/IDerivation' export {default as iterateAndCountTicks} from './derivations/iterateAndCountTicks' export {default as iterateOver} from './derivations/iterateOver' export {default as prism} from './derivations/prism/prism' diff --git a/packages/react/src/index.ts b/packages/react/src/index.ts index 86777fb..a72781b 100644 --- a/packages/react/src/index.ts +++ b/packages/react/src/index.ts @@ -4,7 +4,7 @@ * @packageDocumentation */ -import type {IDerivation} from '@theatre/dataverse' +import type {Prism} from '@theatre/dataverse' import {Box} from '@theatre/dataverse' import {prism, val} from '@theatre/dataverse' import {findIndex} from 'lodash-es' @@ -144,7 +144,7 @@ type QueueItem = { /** * A reference to the derivation */ - der: IDerivation + der: Prism /** * The last value of this derivation. */ @@ -303,7 +303,7 @@ function queueIfNeeded() { * On the off-chance that one of them still turns out to be a zombile child, `runQueue` will defer that particular * `useDerivation()` to be read inside a normal react render phase. */ -export function useDerivation(der: IDerivation, debugLabel?: string): T { +export function useDerivation(der: Prism, debugLabel?: string): T { const _forceUpdate = useForceUpdate(debugLabel) const ref = useRef>(undefined as $IntentionalAny) @@ -386,7 +386,7 @@ export function useDerivation(der: IDerivation, debugLabel?: string): T { export function usePrismWithoutReRender( fn: () => T, deps: unknown[], -): IDerivation { +): Prism { const derivation = useMemo(() => prism(fn), deps) return useDerivationWithoutReRender(derivation) @@ -398,9 +398,7 @@ export function usePrismWithoutReRender( * return the value of the derivation, and it does not * re-render the component if the value of the derivation changes. */ -export function useDerivationWithoutReRender( - der: IDerivation, -): IDerivation { +export function useDerivationWithoutReRender(der: Prism): Prism { useEffect(() => { const untap = der.keepHot() diff --git a/theatre/core/src/projects/initialiseProjectState.ts b/theatre/core/src/projects/initialiseProjectState.ts index 71fa3a4..7da82b0 100644 --- a/theatre/core/src/projects/initialiseProjectState.ts +++ b/theatre/core/src/projects/initialiseProjectState.ts @@ -8,7 +8,7 @@ import globals from '@theatre/shared/globals' /** * @remarks * TODO this could be turned into a simple derivation, like: - * `editor.isReady: IDerivation<{isReady: true} | {isReady: false, reason: 'conflictBetweenDiskStateAndBrowserState'}>` + * `editor.isReady: Prism<{isReady: true} | {isReady: false, reason: 'conflictBetweenDiskStateAndBrowserState'}>` */ export default async function initialiseProjectState( studio: Studio, diff --git a/theatre/core/src/sequences/Sequence.ts b/theatre/core/src/sequences/Sequence.ts index b1b8ab5..668cf3b 100644 --- a/theatre/core/src/sequences/Sequence.ts +++ b/theatre/core/src/sequences/Sequence.ts @@ -3,7 +3,7 @@ import type Sheet from '@theatre/core/sheets/Sheet' import type {SequenceAddress} from '@theatre/shared/utils/addresses' import didYouMean from '@theatre/shared/utils/didYouMean' import {InvalidArgumentError} from '@theatre/shared/utils/errors' -import type {IBox, IDerivation, Pointer} from '@theatre/dataverse' +import type {IBox, Prism, Pointer} from '@theatre/dataverse' import {pointer} from '@theatre/dataverse' import {Box, prism, val} from '@theatre/dataverse' import {padStart} from 'lodash-es' @@ -38,10 +38,10 @@ export default class Sequence { publicApi: TheatreSequence private _playbackControllerBox: IBox - private _statePointerDerivation: IDerivation> - private _positionD: IDerivation - private _positionFormatterD: IDerivation - _playableRangeD: undefined | IDerivation<{start: number; end: number}> + private _statePointerDerivation: Prism> + private _positionD: Prism + private _positionFormatterD: Prism + _playableRangeD: undefined | Prism<{start: number; end: number}> readonly pointer: ISequence['pointer'] = pointer({root: this, path: []}) readonly $$isIdentityDerivationProvider = true @@ -50,8 +50,8 @@ export default class Sequence { constructor( readonly _project: Project, readonly _sheet: Sheet, - readonly _lengthD: IDerivation, - readonly _subUnitsPerUnitD: IDerivation, + readonly _lengthD: Prism, + readonly _subUnitsPerUnitD: Prism, playbackController?: IPlaybackController, ) { this._logger = _project._logger @@ -81,7 +81,7 @@ export default class Sequence { }) } - getIdentityDerivation(path: Array): IDerivation { + getIdentityDerivation(path: Array): Prism { if (path.length === 0) { return prism((): ISequence['pointer']['$$__pointer_type'] => ({ length: val(this.pointer.length), @@ -177,7 +177,7 @@ export default class Sequence { return val(this._playbackControllerBox.get().statePointer.playing) } - _makeRangeFromSequenceTemplate(): IDerivation { + _makeRangeFromSequenceTemplate(): Prism { return prism(() => { return [0, val(this._lengthD)] }) @@ -194,7 +194,7 @@ export default class Sequence { * @returns a promise that gets rejected if the playback stopped for whatever reason * */ - playDynamicRange(rangeD: IDerivation): Promise { + playDynamicRange(rangeD: Prism): Promise { return this._playbackControllerBox.get().playDynamicRange(rangeD) } diff --git a/theatre/core/src/sequences/interpolationTripleAtPosition.ts b/theatre/core/src/sequences/interpolationTripleAtPosition.ts index 642a7ca..fab4415 100644 --- a/theatre/core/src/sequences/interpolationTripleAtPosition.ts +++ b/theatre/core/src/sequences/interpolationTripleAtPosition.ts @@ -3,7 +3,7 @@ import type { Keyframe, TrackData, } from '@theatre/core/projects/store/types/SheetState_Historic' -import type {IDerivation, Pointer} from '@theatre/dataverse' +import type {Prism, Pointer} from '@theatre/dataverse' import {prism, val} from '@theatre/dataverse' import type {IUtilContext} from '@theatre/shared/logger' import type {SerializableValue} from '@theatre/shared/utils/types' @@ -28,8 +28,8 @@ export type InterpolationTriple = { export default function interpolationTripleAtPosition( ctx: IUtilContext, trackP: Pointer, - timeD: IDerivation, -): IDerivation { + timeD: Prism, +): Prism { return prism(() => { const track = val(trackP) const driverD = prism.memo( @@ -55,7 +55,7 @@ type IStartedState = { started: true validFrom: number validTo: number - der: IDerivation + der: Prism } type IState = {started: false} | IStartedState @@ -63,8 +63,8 @@ type IState = {started: false} | IStartedState function _forKeyframedTrack( ctx: IUtilContext, track: BasicKeyframedTrack, - timeD: IDerivation, -): IDerivation { + timeD: Prism, +): Prism { return prism(() => { let stateRef = prism.ref('state', {started: false}) let state = stateRef.current @@ -83,7 +83,7 @@ const undefinedConstD = prism(() => undefined) function updateState( ctx: IUtilContext, - progressionD: IDerivation, + progressionD: Prism, track: BasicKeyframedTrack, ): IStartedState { const progression = progressionD.getValue() @@ -173,7 +173,7 @@ const states = { between( left: Keyframe, right: Keyframe, - progressionD: IDerivation, + progressionD: Prism, ): IStartedState { if (!left.connectedRight) { return { diff --git a/theatre/core/src/sequences/playbackControllers/AudioPlaybackController.ts b/theatre/core/src/sequences/playbackControllers/AudioPlaybackController.ts index 53f6138..23a020d 100644 --- a/theatre/core/src/sequences/playbackControllers/AudioPlaybackController.ts +++ b/theatre/core/src/sequences/playbackControllers/AudioPlaybackController.ts @@ -5,7 +5,7 @@ import type { import {defer} from '@theatre/shared/utils/defer' import {InvalidArgumentError} from '@theatre/shared/utils/errors' import noop from '@theatre/shared/utils/noop' -import type {IDerivation, Pointer, Ticker} from '@theatre/dataverse' +import type {Prism, Pointer, Ticker} from '@theatre/dataverse' import {Atom} from '@theatre/dataverse' import type { IPlaybackController, @@ -34,7 +34,7 @@ export default class AudioPlaybackController implements IPlaybackController { this._mainGain.connect(this._nodeDestination) } - playDynamicRange(rangeD: IDerivation): Promise { + playDynamicRange(rangeD: Prism): Promise { const deferred = defer() if (this._playing) this.pause() diff --git a/theatre/core/src/sequences/playbackControllers/DefaultPlaybackController.ts b/theatre/core/src/sequences/playbackControllers/DefaultPlaybackController.ts index 9385b98..1023de0 100644 --- a/theatre/core/src/sequences/playbackControllers/DefaultPlaybackController.ts +++ b/theatre/core/src/sequences/playbackControllers/DefaultPlaybackController.ts @@ -4,7 +4,7 @@ import type { } from '@theatre/core/sequences/Sequence' import {defer} from '@theatre/shared/utils/defer' import noop from '@theatre/shared/utils/noop' -import type {IDerivation, Pointer, Ticker} from '@theatre/dataverse' +import type {Prism, Pointer, Ticker} from '@theatre/dataverse' import {Atom} from '@theatre/dataverse' export interface IPlaybackState { @@ -36,7 +36,7 @@ export interface IPlaybackController { * @returns a promise that gets rejected if the playback stopped for whatever reason * */ - playDynamicRange(rangeD: IDerivation): Promise + playDynamicRange(rangeD: Prism): Promise pause(): void } @@ -203,7 +203,7 @@ export default class DefaultPlaybackController implements IPlaybackController { return deferred.promise } - playDynamicRange(rangeD: IDerivation): Promise { + playDynamicRange(rangeD: Prism): Promise { if (this.playing) { this.pause() } diff --git a/theatre/core/src/sheetObjects/SheetObject.ts b/theatre/core/src/sheetObjects/SheetObject.ts index 74b5c93..296085d 100644 --- a/theatre/core/src/sheetObjects/SheetObject.ts +++ b/theatre/core/src/sheetObjects/SheetObject.ts @@ -16,7 +16,7 @@ import type { import {valToAtom} from '@theatre/shared/utils/valToAtom' import type { IdentityDerivationProvider, - IDerivation, + Prism, Pointer, } from '@theatre/dataverse' @@ -73,7 +73,7 @@ export default class SheetObject implements IdentityDerivationProvider { this.publicApi = new TheatreSheetObject(this) } - getValues(): IDerivation> { + getValues(): Prism> { // Cache the derivation because only one is needed per SheetObject. // Also, if `onValuesChange()` is unsubscribed from, this derivation will go cold // and free its resources. So it's no problem to still keep it on the cache. @@ -215,7 +215,7 @@ export default class SheetObject implements IdentityDerivationProvider { ) as SerializableValue as T } - getIdentityDerivation(path: Array): IDerivation { + getIdentityDerivation(path: Array): Prism { /** * @remarks * TODO perf: Too much indirection here. @@ -229,7 +229,7 @@ export default class SheetObject implements IdentityDerivationProvider { /** * Returns values of props that are sequenced. */ - getSequencedValues(): IDerivation> { + getSequencedValues(): Prism> { return prism(() => { const tracksToProcessD = prism.memo( 'tracksToProcess', @@ -305,7 +305,7 @@ export default class SheetObject implements IdentityDerivationProvider { protected _trackIdToDerivation( trackId: SequenceTrackId, - ): IDerivation { + ): Prism { const trackP = this.template.project.pointers.historic.sheetsById[this.address.sheetId] .sequence.tracksByObject[this.address.objectKey].trackData[trackId] diff --git a/theatre/core/src/sheetObjects/SheetObjectTemplate.ts b/theatre/core/src/sheetObjects/SheetObjectTemplate.ts index ca39242..abe5a63 100644 --- a/theatre/core/src/sheetObjects/SheetObjectTemplate.ts +++ b/theatre/core/src/sheetObjects/SheetObjectTemplate.ts @@ -21,7 +21,7 @@ import type { SerializableMap, SerializableValue, } from '@theatre/shared/utils/types' -import type {IDerivation, Pointer} from '@theatre/dataverse' +import type {Prism, Pointer} from '@theatre/dataverse' import {Atom, getPointerParts, prism, val} from '@theatre/dataverse' import set from 'lodash-es/set' import getPropDefaultsOfSheetObject from './getPropDefaultsOfSheetObject' @@ -115,7 +115,7 @@ export default class SheetObjectTemplate { /** * Returns the default values (all defaults are read from the config) */ - getDefaultValues(): IDerivation { + getDefaultValues(): Prism { return this._cache.get('getDefaultValues()', () => prism(() => { const config = val(this.configPointer) @@ -127,7 +127,7 @@ export default class SheetObjectTemplate { /** * Returns values that are set statically (ie, not sequenced, and not defaults) */ - getStaticValues(): IDerivation { + getStaticValues(): Prism { return this._cache.get('getDerivationOfStatics', () => prism(() => { const pointerToSheetState = @@ -155,7 +155,7 @@ export default class SheetObjectTemplate { * * Returns an array. */ - getArrayOfValidSequenceTracks(): IDerivation< + getArrayOfValidSequenceTracks(): Prism< Array<{pathToProp: PathToProp; trackId: SequenceTrackId}> > { return this._cache.get('getArrayOfValidSequenceTracks', () => @@ -226,7 +226,7 @@ export default class SheetObjectTemplate { * * Not available in core. */ - getMapOfValidSequenceTracks_forStudio(): IDerivation { + getMapOfValidSequenceTracks_forStudio(): Prism { return this._cache.get('getMapOfValidSequenceTracks_forStudio', () => prism(() => { const arr = val(this.getArrayOfValidSequenceTracks()) diff --git a/theatre/core/src/sheetObjects/TheatreSheetObject.ts b/theatre/core/src/sheetObjects/TheatreSheetObject.ts index 39ff343..57c7d52 100644 --- a/theatre/core/src/sheetObjects/TheatreSheetObject.ts +++ b/theatre/core/src/sheetObjects/TheatreSheetObject.ts @@ -9,7 +9,7 @@ import type { DeepPartialOfSerializableValue, VoidFn, } from '@theatre/shared/utils/types' -import type {IDerivation, Pointer} from '@theatre/dataverse' +import type {Prism, Pointer} from '@theatre/dataverse' import {prism, val} from '@theatre/dataverse' import type SheetObject from './SheetObject' import type { @@ -147,10 +147,10 @@ export default class TheatreSheetObject< return {...privateAPI(this).address} } - private _valuesDerivation(): IDerivation { + private _valuesDerivation(): Prism { return this._cache.get('onValuesChangeDerivation', () => { const sheetObject = privateAPI(this) - const d: IDerivation> = prism(() => { + const d: Prism> = prism(() => { return val(sheetObject.getValues().getValue()) as $FixMe }) return d diff --git a/theatre/studio/src/TheatreStudio.ts b/theatre/studio/src/TheatreStudio.ts index 63ce576..cb38e8b 100644 --- a/theatre/studio/src/TheatreStudio.ts +++ b/theatre/studio/src/TheatreStudio.ts @@ -1,6 +1,6 @@ import type {IProject, ISheet, ISheetObject} from '@theatre/core' import studioTicker from '@theatre/studio/studioTicker' -import type {IDerivation, Pointer} from '@theatre/dataverse' +import type {Prism, Pointer} from '@theatre/dataverse' import {prism} from '@theatre/dataverse' import SimpleCache from '@theatre/shared/utils/SimpleCache' import type {$IntentionalAny, VoidFn} from '@theatre/shared/utils/types' @@ -410,7 +410,7 @@ export default class TheatreStudio implements IStudio { }) } - private _getSelectionDerivation(): IDerivation<(ISheetObject | ISheet)[]> { + private _getSelectionDerivation(): Prism<(ISheetObject | ISheet)[]> { return this._cache.get('_getStateDerivation()', () => prism((): (ISheetObject | ISheet)[] => { return getOutlineSelection() diff --git a/theatre/studio/src/UIRoot/useKeyboardShortcuts.ts b/theatre/studio/src/UIRoot/useKeyboardShortcuts.ts index 0cde428..eb461ea 100644 --- a/theatre/studio/src/UIRoot/useKeyboardShortcuts.ts +++ b/theatre/studio/src/UIRoot/useKeyboardShortcuts.ts @@ -3,7 +3,7 @@ import getStudio from '@theatre/studio/getStudio' import {cmdIsDown} from '@theatre/studio/utils/keyboardUtils' import {getSelectedSequence} from '@theatre/studio/selectors' import type {$IntentionalAny} from '@theatre/shared/utils/types' -import type {IDerivation} from '@theatre/dataverse' +import type {Prism} from '@theatre/dataverse' import {Box, prism, val} from '@theatre/dataverse' import type {IPlaybackRange} from '@theatre/core/sequences/Sequence' import type Sequence from '@theatre/core/sequences/Sequence' @@ -151,7 +151,7 @@ export default function useKeyboardShortcuts() { } type ControlledPlaybackStateBox = Box< - undefined | IDerivation<{range: IPlaybackRange; isFollowingARange: boolean}> + undefined | Prism<{range: IPlaybackRange; isFollowingARange: boolean}> > const getPlaybackStateBox = memoizeFn( diff --git a/theatre/studio/src/panels/DetailPanel/DeterminePropEditorForDetail/SingleRowPropEditor.tsx b/theatre/studio/src/panels/DetailPanel/DeterminePropEditorForDetail/SingleRowPropEditor.tsx index 2fe174c..e79e3d6 100644 --- a/theatre/studio/src/panels/DetailPanel/DeterminePropEditorForDetail/SingleRowPropEditor.tsx +++ b/theatre/studio/src/panels/DetailPanel/DeterminePropEditorForDetail/SingleRowPropEditor.tsx @@ -1,6 +1,6 @@ import type * as propTypes from '@theatre/core/propTypes' import {getPointerParts} from '@theatre/dataverse' -import type {Pointer, IDerivation} from '@theatre/dataverse' +import type {Pointer, Prism} from '@theatre/dataverse' import useContextMenu from '@theatre/studio/uiComponents/simpleContextMenu/useContextMenu' import useRefAndState from '@theatre/studio/utils/useRefAndState' import {last} from 'lodash-es' @@ -92,7 +92,7 @@ type ISingleRowPropEditorProps = { propConfig: propTypes.PropTypeConfig pointerToProp: Pointer editingTools: ReturnType - isPropHighlightedD: IDerivation + isPropHighlightedD: Prism } export function SingleRowPropEditor({ diff --git a/theatre/studio/src/panels/SequenceEditorPanel/DopeSheet/Right/AggregatedKeyframeTrack/AggregatedKeyframeTrack.tsx b/theatre/studio/src/panels/SequenceEditorPanel/DopeSheet/Right/AggregatedKeyframeTrack/AggregatedKeyframeTrack.tsx index a2fa8db..a083265 100644 --- a/theatre/studio/src/panels/SequenceEditorPanel/DopeSheet/Right/AggregatedKeyframeTrack/AggregatedKeyframeTrack.tsx +++ b/theatre/studio/src/panels/SequenceEditorPanel/DopeSheet/Right/AggregatedKeyframeTrack/AggregatedKeyframeTrack.tsx @@ -8,7 +8,7 @@ import type { SequenceEditorTree_SheetObject, } from '@theatre/studio/panels/SequenceEditorPanel/layout/tree' import {usePrism, useVal} from '@theatre/react' -import type {IDerivation, Pointer} from '@theatre/dataverse' +import type {Prism, Pointer} from '@theatre/dataverse' import {prism, val, valueDerivation} from '@theatre/dataverse' import React, {useMemo, Fragment} from 'react' import styled from 'styled-components' @@ -230,7 +230,7 @@ function useCollectedSelectedPositions( function collectedSelectedPositions( layoutP: Pointer, aggregatedKeyframes: AggregatedKeyframes, -): IDerivation<_AggSelection> { +): Prism<_AggSelection> { return prism(() => { const selectionAtom = val(layoutP.selectionAtom) const selection = val(selectionAtom.pointer.current) diff --git a/theatre/studio/src/panels/SequenceEditorPanel/DopeSheet/selections.ts b/theatre/studio/src/panels/SequenceEditorPanel/DopeSheet/selections.ts index 7af802a..3167c0d 100644 --- a/theatre/studio/src/panels/SequenceEditorPanel/DopeSheet/selections.ts +++ b/theatre/studio/src/panels/SequenceEditorPanel/DopeSheet/selections.ts @@ -1,4 +1,4 @@ -import type {IDerivation} from '@theatre/dataverse' +import type {Prism} from '@theatre/dataverse' import {prism, val} from '@theatre/dataverse' import type { KeyframeId, @@ -53,7 +53,7 @@ export function selectedKeyframeConnections( projectId: ProjectId, sheetId: SheetId, selection: DopeSheetSelection | undefined, -): IDerivation> { +): Prism> { return prism(() => { if (selection === undefined) return [] diff --git a/theatre/studio/src/panels/SequenceEditorPanel/FrameStampPositionProvider.tsx b/theatre/studio/src/panels/SequenceEditorPanel/FrameStampPositionProvider.tsx index 866c254..0a21482 100644 --- a/theatre/studio/src/panels/SequenceEditorPanel/FrameStampPositionProvider.tsx +++ b/theatre/studio/src/panels/SequenceEditorPanel/FrameStampPositionProvider.tsx @@ -1,4 +1,4 @@ -import type {IDerivation, Pointer} from '@theatre/dataverse' +import type {Prism, Pointer} from '@theatre/dataverse' import {Atom, prism, val} from '@theatre/dataverse' import mousePositionD from '@theatre/studio/utils/mousePositionD' import type {$IntentionalAny} from '@theatre/shared/utils/types' @@ -26,7 +26,7 @@ export enum FrameStampPositionType { } const context = createContext<{ - currentD: IDerivation<[pos: number, posType: FrameStampPositionType]> + currentD: Prism<[pos: number, posType: FrameStampPositionType]> getLock(): FrameStampPositionLock }>(null as $IntentionalAny) @@ -211,7 +211,7 @@ const ATTR_LOCK_FRAMESTAMP = 'data-theatre-lock-framestamp-to' const pointerPositionInUnitSpace = ( layoutP: Pointer, -): IDerivation<[pos: number, posType: FrameStampPositionType]> => { +): Prism<[pos: number, posType: FrameStampPositionType]> => { return prism(() => { const rightDims = val(layoutP.rightDims) const clippedSpaceToUnitSpace = val(layoutP.clippedSpace.toUnitSpace) diff --git a/theatre/studio/src/panels/SequenceEditorPanel/layout/layout.ts b/theatre/studio/src/panels/SequenceEditorPanel/layout/layout.ts index 5318c11..6b71fb5 100644 --- a/theatre/studio/src/panels/SequenceEditorPanel/layout/layout.ts +++ b/theatre/studio/src/panels/SequenceEditorPanel/layout/layout.ts @@ -9,7 +9,7 @@ import type { StrictRecord, } from '@theatre/shared/utils/types' import {valToAtom} from '@theatre/shared/utils/valToAtom' -import type {IDerivation, Pointer} from '@theatre/dataverse' +import type {Prism, Pointer} from '@theatre/dataverse' import {Atom, prism, val} from '@theatre/dataverse' import type {SequenceEditorTree} from './tree' import {calculateSequenceEditorTree} from './tree' @@ -176,7 +176,7 @@ const initialClippedSpaceRange: IRange = {start: 0, end: 10} export function sequenceEditorPanelLayout( sheet: Sheet, panelDimsP: Pointer, -): IDerivation> { +): Prism> { const studio = getStudio()! const ahistoricStateP = diff --git a/theatre/studio/src/panels/SequenceEditorPanel/whatPropIsHighlighted.ts b/theatre/studio/src/panels/SequenceEditorPanel/whatPropIsHighlighted.ts index 0f0207f..90ce749 100644 --- a/theatre/studio/src/panels/SequenceEditorPanel/whatPropIsHighlighted.ts +++ b/theatre/studio/src/panels/SequenceEditorPanel/whatPropIsHighlighted.ts @@ -1,4 +1,4 @@ -import type {IDerivation} from '@theatre/dataverse' +import type {Prism} from '@theatre/dataverse' import {val} from '@theatre/dataverse' import {Atom} from '@theatre/dataverse' import {prism} from '@theatre/dataverse' @@ -57,7 +57,7 @@ function createWhatPropIsHighlightedState() { }, getIsPropHighlightedD( address: WithoutSheetInstance, - ): IDerivation { + ): Prism { const highlightedP = pointerDeep( whatIsHighlighted.pointer.deepPath, addressToArray(address), diff --git a/theatre/studio/src/propEditors/useEditingToolsForSimpleProp.tsx b/theatre/studio/src/propEditors/useEditingToolsForSimpleProp.tsx index 65ff7a7..153104f 100644 --- a/theatre/studio/src/propEditors/useEditingToolsForSimpleProp.tsx +++ b/theatre/studio/src/propEditors/useEditingToolsForSimpleProp.tsx @@ -1,6 +1,6 @@ import get from 'lodash-es/get' import React from 'react' -import type {IDerivation, Pointer} from '@theatre/dataverse' +import type {Prism, Pointer} from '@theatre/dataverse' import {getPointerParts, prism, val} from '@theatre/dataverse' import type SheetObject from '@theatre/core/sheetObjects/SheetObject' import getStudio from '@theatre/studio/getStudio' @@ -59,7 +59,7 @@ type EditingTools = | EditingToolsStatic | EditingToolsSequenced -const cache = new WeakMap<{}, IDerivation>>() +const cache = new WeakMap<{}, Prism>>() /** * Note: we're able to get `obj` and `propConfig` from `pointerToProp`, @@ -69,7 +69,7 @@ function createDerivation( pointerToProp: Pointer, obj: SheetObject, propConfig: PropTypeConfig_AllSimples, -): IDerivation> { +): Prism> { return prism(() => { const pathToProp = getPointerParts(pointerToProp).path @@ -329,7 +329,7 @@ function getDerivation( pointerToProp: Pointer, obj: SheetObject, propConfig: PropTypeConfig_AllSimples, -): IDerivation> { +): Prism> { if (cache.has(pointerToProp)) { return cache.get(pointerToProp)! } else { diff --git a/theatre/studio/src/uiComponents/Popover/TooltipContext.tsx b/theatre/studio/src/uiComponents/Popover/TooltipContext.tsx index 1fc2450..e7dc418 100644 --- a/theatre/studio/src/uiComponents/Popover/TooltipContext.tsx +++ b/theatre/studio/src/uiComponents/Popover/TooltipContext.tsx @@ -1,4 +1,4 @@ -import type {IDerivation} from '@theatre/dataverse' +import type {Prism} from '@theatre/dataverse' import {Box} from '@theatre/dataverse' import useRefAndState from '@theatre/studio/utils/useRefAndState' import React, { @@ -10,7 +10,7 @@ import React, { } from 'react' const ctx = createContext<{ - cur: IDerivation + cur: Prism set: (id: number, delay: number) => void }>(null!) diff --git a/theatre/studio/src/utils/derive-utils.tsx b/theatre/studio/src/utils/derive-utils.tsx index 2c83668..a3f3c31 100644 --- a/theatre/studio/src/utils/derive-utils.tsx +++ b/theatre/studio/src/utils/derive-utils.tsx @@ -1,17 +1,17 @@ import {isDerivation, prism, val} from '@theatre/dataverse' -import type {IDerivation, Pointer} from '@theatre/dataverse' +import type {Prism, Pointer} from '@theatre/dataverse' import {useDerivation} from '@theatre/react' import type {$IntentionalAny} from '@theatre/shared/utils/types' import React, {useMemo, useRef} from 'react' import {invariant} from './invariant' -type DeriveAll = IDerivation< +type DeriveAll = Prism< { [P in keyof T]: T[P] extends $ ? R : never } > -export type $ = IDerivation | Pointer +export type $ = Prism | Pointer function deriveAllD[]]>(obj: T): DeriveAll function deriveAllD>>(obj: T): DeriveAll @@ -40,9 +40,9 @@ interface TSErrors extends Error {} type ReactDeriver = ( props: { - [P in keyof Props]: Props[P] extends IDerivation + [P in keyof Props]: Props[P] extends Prism ? TSErrors<"Can't both use Derivation properties while wrapping with deriver"> - : Props[P] | IDerivation + : Props[P] | Prism }, ) => React.ReactElement | null @@ -64,7 +64,7 @@ export function deriver( ref, ) { let observableArr = [] - const observables: Record> = {} + const observables: Record> = {} const normalProps: Record = { ref, }