Unify Derivation and Prism (1/n)
This commit is contained in:
parent
e9bbb0ef41
commit
12b3f477bc
28 changed files with 109 additions and 116 deletions
|
@ -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<string | number>): IDerivation<unknown>
|
||||
getIdentityDerivation(path: Array<string | number>): Prism<unknown>
|
||||
}
|
||||
|
||||
const getTypeOfValue = (v: unknown): ValueTypes => {
|
||||
|
@ -246,7 +246,7 @@ export default class Atom<State extends {}>
|
|||
*
|
||||
* @param path - The path to create the derivation at.
|
||||
*/
|
||||
getIdentityDerivation(path: Array<string | number>): IDerivation<unknown> {
|
||||
getIdentityDerivation(path: Array<string | number>): Prism<unknown> {
|
||||
const subscribe = (listener: (val: unknown) => void) =>
|
||||
this._onPathValueChange(path, listener)
|
||||
|
||||
|
@ -258,7 +258,7 @@ export default class Atom<State extends {}>
|
|||
}
|
||||
}
|
||||
|
||||
const identityDerivationWeakMap = new WeakMap<{}, IDerivation<unknown>>()
|
||||
const identityDerivationWeakMap = new WeakMap<{}, Prism<unknown>>()
|
||||
|
||||
/**
|
||||
* Returns a derivation of the value at the provided pointer. Derivations are
|
||||
|
@ -268,7 +268,7 @@ const identityDerivationWeakMap = new WeakMap<{}, IDerivation<unknown>>()
|
|||
*/
|
||||
export const valueDerivation = <P extends PointerType<$IntentionalAny>>(
|
||||
pointer: P,
|
||||
): IDerivation<P extends PointerType<infer T> ? T : void> => {
|
||||
): Prism<P extends PointerType<infer T> ? 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<infer T>
|
||||
? T
|
||||
: P extends IDerivation<infer T>
|
||||
: P extends Prism<infer T>
|
||||
? T
|
||||
: P extends undefined | null
|
||||
? P
|
||||
|
|
|
@ -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<V> {
|
|||
/**
|
||||
* Creates a derivation of the Box that you can use to track changes to it.
|
||||
*/
|
||||
derivation: IDerivation<V>
|
||||
derivation: Prism<V>
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -39,7 +39,7 @@ export interface IBox<V> {
|
|||
* reference even if the objects are structurally equal.
|
||||
*/
|
||||
export default class Box<V> implements IBox<V> {
|
||||
private _publicDerivation: IDerivation<V>
|
||||
private _publicDerivation: Prism<V>
|
||||
private _emitter = new Emitter<V>()
|
||||
|
||||
/**
|
||||
|
|
|
@ -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<V> {
|
||||
export interface Prism<V> {
|
||||
/**
|
||||
* Whether the object is a derivation.
|
||||
*/
|
||||
|
@ -63,6 +63,6 @@ export interface IDerivation<V> {
|
|||
/**
|
||||
* Returns whether `d` is a derivation.
|
||||
*/
|
||||
export function isDerivation(d: any): d is IDerivation<unknown> {
|
||||
export function isDerivation(d: any): d is Prism<unknown> {
|
||||
return d && d.isDerivation && d.isDerivation === true
|
||||
}
|
||||
|
|
|
@ -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<V>(
|
||||
pointerOrDerivation: IDerivation<V> | Pointer<V>,
|
||||
pointerOrDerivation: Prism<V> | Pointer<V>,
|
||||
): Generator<{value: V; ticks: number}, void, void> {
|
||||
let d
|
||||
if (isPointer(pointerOrDerivation)) {
|
||||
d = valueDerivation(pointerOrDerivation) as IDerivation<V>
|
||||
d = valueDerivation(pointerOrDerivation) as Prism<V>
|
||||
} else if (isDerivation(pointerOrDerivation)) {
|
||||
d = pointerOrDerivation
|
||||
} else {
|
||||
|
|
|
@ -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<V>(
|
||||
pointerOrDerivation: IDerivation<V> | Pointer<V>,
|
||||
pointerOrDerivation: Prism<V> | Pointer<V>,
|
||||
): Generator<V, void, void> {
|
||||
let d
|
||||
if (isPointer(pointerOrDerivation)) {
|
||||
d = valueDerivation(pointerOrDerivation) as IDerivation<V>
|
||||
d = valueDerivation(pointerOrDerivation) as Prism<V>
|
||||
} else if (isDerivation(pointerOrDerivation)) {
|
||||
d = pointerOrDerivation
|
||||
} else {
|
||||
|
|
|
@ -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<Collector>()
|
||||
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()
|
||||
}
|
||||
|
||||
|
|
|
@ -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<V> {
|
||||
private _didMarkDependentsAsStale: boolean = false
|
||||
private _isFresh: boolean = false
|
||||
protected _cacheOfDendencyValues: Map<IDerivation<unknown>, unknown> =
|
||||
new Map()
|
||||
protected _cacheOfDendencyValues: Map<Prism<unknown>, unknown> = new Map()
|
||||
|
||||
/**
|
||||
* @internal
|
||||
|
@ -30,9 +29,9 @@ class HotHandle<V> {
|
|||
/**
|
||||
* @internal
|
||||
*/
|
||||
protected _dependencies: Set<IDerivation<$IntentionalAny>> = new Set()
|
||||
protected _dependencies: Set<Prism<$IntentionalAny>> = new Set()
|
||||
|
||||
protected _possiblyStaleDeps = new Set<IDerivation<unknown>>()
|
||||
protected _possiblyStaleDeps = new Set<Prism<unknown>>()
|
||||
|
||||
private _scope: HotScope = new HotScope(
|
||||
this as $IntentionalAny as HotHandle<unknown>,
|
||||
|
@ -112,10 +111,10 @@ class HotHandle<V> {
|
|||
}
|
||||
}
|
||||
|
||||
const newDeps: Set<IDerivation<unknown>> = new Set()
|
||||
const newDeps: Set<Prism<unknown>> = new Set()
|
||||
this._cacheOfDendencyValues.clear()
|
||||
|
||||
const collector = (observedDep: IDerivation<unknown>): void => {
|
||||
const collector = (observedDep: Prism<unknown>): void => {
|
||||
newDeps.add(observedDep)
|
||||
this._addDependency(observedDep)
|
||||
}
|
||||
|
@ -161,9 +160,7 @@ class HotHandle<V> {
|
|||
this._markAsStale()
|
||||
}
|
||||
|
||||
protected _reactToDependencyGoingStale = (
|
||||
which: IDerivation<$IntentionalAny>,
|
||||
) => {
|
||||
protected _reactToDependencyGoingStale = (which: Prism<$IntentionalAny>) => {
|
||||
this._possiblyStaleDeps.add(which)
|
||||
|
||||
this._markAsStale()
|
||||
|
@ -183,7 +180,7 @@ class HotHandle<V> {
|
|||
/**
|
||||
* @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<V> {
|
|||
/**
|
||||
* @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<V> {
|
|||
|
||||
const emptyObject = {}
|
||||
|
||||
class PrismDerivation<V> implements IDerivation<V> {
|
||||
class PrismDerivation<V> implements Prism<V> {
|
||||
/**
|
||||
* 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 = <P extends Prism<$IntentionalAny> | unknown>(
|
||||
input: P,
|
||||
): P extends IDerivation<infer T> ? T : P => {
|
||||
): P extends Prism<infer T> ? T : P => {
|
||||
if (isDerivation(input)) {
|
||||
return input.getValue() as $IntentionalAny
|
||||
} else {
|
||||
|
@ -728,7 +723,7 @@ function source<V>(
|
|||
}
|
||||
|
||||
type IPrismFn = {
|
||||
<T>(fn: () => T): IDerivation<T>
|
||||
<T>(fn: () => T): Prism<T>
|
||||
ref: typeof ref
|
||||
effect: typeof effect
|
||||
memo: typeof memo
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -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<T = unknown> = {
|
|||
/**
|
||||
* A reference to the derivation
|
||||
*/
|
||||
der: IDerivation<T>
|
||||
der: Prism<T>
|
||||
/**
|
||||
* 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<T>(der: IDerivation<T>, debugLabel?: string): T {
|
||||
export function useDerivation<T>(der: Prism<T>, debugLabel?: string): T {
|
||||
const _forceUpdate = useForceUpdate(debugLabel)
|
||||
|
||||
const ref = useRef<QueueItem<T>>(undefined as $IntentionalAny)
|
||||
|
@ -386,7 +386,7 @@ export function useDerivation<T>(der: IDerivation<T>, debugLabel?: string): T {
|
|||
export function usePrismWithoutReRender<T>(
|
||||
fn: () => T,
|
||||
deps: unknown[],
|
||||
): IDerivation<T> {
|
||||
): Prism<T> {
|
||||
const derivation = useMemo(() => prism(fn), deps)
|
||||
|
||||
return useDerivationWithoutReRender(derivation)
|
||||
|
@ -398,9 +398,7 @@ export function usePrismWithoutReRender<T>(
|
|||
* return the value of the derivation, and it does not
|
||||
* re-render the component if the value of the derivation changes.
|
||||
*/
|
||||
export function useDerivationWithoutReRender<T>(
|
||||
der: IDerivation<T>,
|
||||
): IDerivation<T> {
|
||||
export function useDerivationWithoutReRender<T>(der: Prism<T>): Prism<T> {
|
||||
useEffect(() => {
|
||||
const untap = der.keepHot()
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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<IPlaybackController>
|
||||
private _statePointerDerivation: IDerivation<Pointer<IPlaybackState>>
|
||||
private _positionD: IDerivation<number>
|
||||
private _positionFormatterD: IDerivation<ISequencePositionFormatter>
|
||||
_playableRangeD: undefined | IDerivation<{start: number; end: number}>
|
||||
private _statePointerDerivation: Prism<Pointer<IPlaybackState>>
|
||||
private _positionD: Prism<number>
|
||||
private _positionFormatterD: Prism<ISequencePositionFormatter>
|
||||
_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<number>,
|
||||
readonly _subUnitsPerUnitD: IDerivation<number>,
|
||||
readonly _lengthD: Prism<number>,
|
||||
readonly _subUnitsPerUnitD: Prism<number>,
|
||||
playbackController?: IPlaybackController,
|
||||
) {
|
||||
this._logger = _project._logger
|
||||
|
@ -81,7 +81,7 @@ export default class Sequence {
|
|||
})
|
||||
}
|
||||
|
||||
getIdentityDerivation(path: Array<string | number>): IDerivation<unknown> {
|
||||
getIdentityDerivation(path: Array<string | number>): Prism<unknown> {
|
||||
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<IPlaybackRange> {
|
||||
_makeRangeFromSequenceTemplate(): Prism<IPlaybackRange> {
|
||||
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<IPlaybackRange>): Promise<unknown> {
|
||||
playDynamicRange(rangeD: Prism<IPlaybackRange>): Promise<unknown> {
|
||||
return this._playbackControllerBox.get().playDynamicRange(rangeD)
|
||||
}
|
||||
|
||||
|
|
|
@ -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<TrackData | undefined>,
|
||||
timeD: IDerivation<number>,
|
||||
): IDerivation<InterpolationTriple | undefined> {
|
||||
timeD: Prism<number>,
|
||||
): Prism<InterpolationTriple | undefined> {
|
||||
return prism(() => {
|
||||
const track = val(trackP)
|
||||
const driverD = prism.memo(
|
||||
|
@ -55,7 +55,7 @@ type IStartedState = {
|
|||
started: true
|
||||
validFrom: number
|
||||
validTo: number
|
||||
der: IDerivation<InterpolationTriple | undefined>
|
||||
der: Prism<InterpolationTriple | undefined>
|
||||
}
|
||||
|
||||
type IState = {started: false} | IStartedState
|
||||
|
@ -63,8 +63,8 @@ type IState = {started: false} | IStartedState
|
|||
function _forKeyframedTrack(
|
||||
ctx: IUtilContext,
|
||||
track: BasicKeyframedTrack,
|
||||
timeD: IDerivation<number>,
|
||||
): IDerivation<InterpolationTriple | undefined> {
|
||||
timeD: Prism<number>,
|
||||
): Prism<InterpolationTriple | undefined> {
|
||||
return prism(() => {
|
||||
let stateRef = prism.ref<IState>('state', {started: false})
|
||||
let state = stateRef.current
|
||||
|
@ -83,7 +83,7 @@ const undefinedConstD = prism(() => undefined)
|
|||
|
||||
function updateState(
|
||||
ctx: IUtilContext,
|
||||
progressionD: IDerivation<number>,
|
||||
progressionD: Prism<number>,
|
||||
track: BasicKeyframedTrack,
|
||||
): IStartedState {
|
||||
const progression = progressionD.getValue()
|
||||
|
@ -173,7 +173,7 @@ const states = {
|
|||
between(
|
||||
left: Keyframe,
|
||||
right: Keyframe,
|
||||
progressionD: IDerivation<number>,
|
||||
progressionD: Prism<number>,
|
||||
): IStartedState {
|
||||
if (!left.connectedRight) {
|
||||
return {
|
||||
|
|
|
@ -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<IPlaybackRange>): Promise<unknown> {
|
||||
playDynamicRange(rangeD: Prism<IPlaybackRange>): Promise<unknown> {
|
||||
const deferred = defer<boolean>()
|
||||
if (this._playing) this.pause()
|
||||
|
||||
|
|
|
@ -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<IPlaybackRange>): Promise<unknown>
|
||||
playDynamicRange(rangeD: Prism<IPlaybackRange>): Promise<unknown>
|
||||
|
||||
pause(): void
|
||||
}
|
||||
|
@ -203,7 +203,7 @@ export default class DefaultPlaybackController implements IPlaybackController {
|
|||
return deferred.promise
|
||||
}
|
||||
|
||||
playDynamicRange(rangeD: IDerivation<IPlaybackRange>): Promise<unknown> {
|
||||
playDynamicRange(rangeD: Prism<IPlaybackRange>): Promise<unknown> {
|
||||
if (this.playing) {
|
||||
this.pause()
|
||||
}
|
||||
|
|
|
@ -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<Pointer<SheetObjectPropsValue>> {
|
||||
getValues(): Prism<Pointer<SheetObjectPropsValue>> {
|
||||
// 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<string | number>): IDerivation<unknown> {
|
||||
getIdentityDerivation(path: Array<string | number>): Prism<unknown> {
|
||||
/**
|
||||
* @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<Pointer<SheetObjectPropsValue>> {
|
||||
getSequencedValues(): Prism<Pointer<SheetObjectPropsValue>> {
|
||||
return prism(() => {
|
||||
const tracksToProcessD = prism.memo(
|
||||
'tracksToProcess',
|
||||
|
@ -305,7 +305,7 @@ export default class SheetObject implements IdentityDerivationProvider {
|
|||
|
||||
protected _trackIdToDerivation(
|
||||
trackId: SequenceTrackId,
|
||||
): IDerivation<InterpolationTriple | undefined> {
|
||||
): Prism<InterpolationTriple | undefined> {
|
||||
const trackP =
|
||||
this.template.project.pointers.historic.sheetsById[this.address.sheetId]
|
||||
.sequence.tracksByObject[this.address.objectKey].trackData[trackId]
|
||||
|
|
|
@ -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<SerializableMap> {
|
||||
getDefaultValues(): Prism<SerializableMap> {
|
||||
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<SerializableMap> {
|
||||
getStaticValues(): Prism<SerializableMap> {
|
||||
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<IPropPathToTrackIdTree> {
|
||||
getMapOfValidSequenceTracks_forStudio(): Prism<IPropPathToTrackIdTree> {
|
||||
return this._cache.get('getMapOfValidSequenceTracks_forStudio', () =>
|
||||
prism(() => {
|
||||
const arr = val(this.getArrayOfValidSequenceTracks())
|
||||
|
|
|
@ -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<this['value']> {
|
||||
private _valuesDerivation(): Prism<this['value']> {
|
||||
return this._cache.get('onValuesChangeDerivation', () => {
|
||||
const sheetObject = privateAPI(this)
|
||||
const d: IDerivation<PropsValue<Props>> = prism(() => {
|
||||
const d: Prism<PropsValue<Props>> = prism(() => {
|
||||
return val(sheetObject.getValues().getValue()) as $FixMe
|
||||
})
|
||||
return d
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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<T> = {
|
|||
propConfig: propTypes.PropTypeConfig
|
||||
pointerToProp: Pointer<T>
|
||||
editingTools: ReturnType<typeof useEditingToolsForSimplePropInDetailsPanel>
|
||||
isPropHighlightedD: IDerivation<PropHighlighted>
|
||||
isPropHighlightedD: Prism<PropHighlighted>
|
||||
}
|
||||
|
||||
export function SingleRowPropEditor<T>({
|
||||
|
|
|
@ -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<SequenceEditorPanelLayout>,
|
||||
aggregatedKeyframes: AggregatedKeyframes,
|
||||
): IDerivation<_AggSelection> {
|
||||
): Prism<_AggSelection> {
|
||||
return prism(() => {
|
||||
const selectionAtom = val(layoutP.selectionAtom)
|
||||
const selection = val(selectionAtom.pointer.current)
|
||||
|
|
|
@ -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<Array<KeyframeConnectionWithAddress>> {
|
||||
): Prism<Array<KeyframeConnectionWithAddress>> {
|
||||
return prism(() => {
|
||||
if (selection === undefined) return []
|
||||
|
||||
|
|
|
@ -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<SequenceEditorPanelLayout>,
|
||||
): IDerivation<[pos: number, posType: FrameStampPositionType]> => {
|
||||
): Prism<[pos: number, posType: FrameStampPositionType]> => {
|
||||
return prism(() => {
|
||||
const rightDims = val(layoutP.rightDims)
|
||||
const clippedSpaceToUnitSpace = val(layoutP.clippedSpace.toUnitSpace)
|
||||
|
|
|
@ -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<PanelDims>,
|
||||
): IDerivation<Pointer<SequenceEditorPanelLayout>> {
|
||||
): Prism<Pointer<SequenceEditorPanelLayout>> {
|
||||
const studio = getStudio()!
|
||||
|
||||
const ahistoricStateP =
|
||||
|
|
|
@ -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<PropAddress>,
|
||||
): IDerivation<PropHighlighted> {
|
||||
): Prism<PropHighlighted> {
|
||||
const highlightedP = pointerDeep(
|
||||
whatIsHighlighted.pointer.deepPath,
|
||||
addressToArray(address),
|
||||
|
|
|
@ -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<T> =
|
|||
| EditingToolsStatic<T>
|
||||
| EditingToolsSequenced<T>
|
||||
|
||||
const cache = new WeakMap<{}, IDerivation<EditingTools<$IntentionalAny>>>()
|
||||
const cache = new WeakMap<{}, Prism<EditingTools<$IntentionalAny>>>()
|
||||
|
||||
/**
|
||||
* Note: we're able to get `obj` and `propConfig` from `pointerToProp`,
|
||||
|
@ -69,7 +69,7 @@ function createDerivation<T extends SerializablePrimitive>(
|
|||
pointerToProp: Pointer<T>,
|
||||
obj: SheetObject,
|
||||
propConfig: PropTypeConfig_AllSimples,
|
||||
): IDerivation<EditingTools<T>> {
|
||||
): Prism<EditingTools<T>> {
|
||||
return prism(() => {
|
||||
const pathToProp = getPointerParts(pointerToProp).path
|
||||
|
||||
|
@ -329,7 +329,7 @@ function getDerivation<T extends SerializablePrimitive>(
|
|||
pointerToProp: Pointer<T>,
|
||||
obj: SheetObject,
|
||||
propConfig: PropTypeConfig_AllSimples,
|
||||
): IDerivation<EditingTools<T>> {
|
||||
): Prism<EditingTools<T>> {
|
||||
if (cache.has(pointerToProp)) {
|
||||
return cache.get(pointerToProp)!
|
||||
} else {
|
||||
|
|
|
@ -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<number>
|
||||
cur: Prism<number>
|
||||
set: (id: number, delay: number) => void
|
||||
}>(null!)
|
||||
|
||||
|
|
|
@ -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<T> = IDerivation<
|
||||
type DeriveAll<T> = Prism<
|
||||
{
|
||||
[P in keyof T]: T[P] extends $<infer R> ? R : never
|
||||
}
|
||||
>
|
||||
|
||||
export type $<T> = IDerivation<T> | Pointer<T>
|
||||
export type $<T> = Prism<T> | Pointer<T>
|
||||
|
||||
function deriveAllD<T extends [...$<any>[]]>(obj: T): DeriveAll<T>
|
||||
function deriveAllD<T extends Record<string, $<any>>>(obj: T): DeriveAll<T>
|
||||
|
@ -40,9 +40,9 @@ interface TSErrors<M> extends Error {}
|
|||
|
||||
type ReactDeriver<Props extends {}> = (
|
||||
props: {
|
||||
[P in keyof Props]: Props[P] extends IDerivation<infer _>
|
||||
[P in keyof Props]: Props[P] extends Prism<infer _>
|
||||
? TSErrors<"Can't both use Derivation properties while wrapping with deriver">
|
||||
: Props[P] | IDerivation<Props[P]>
|
||||
: Props[P] | Prism<Props[P]>
|
||||
},
|
||||
) => React.ReactElement | null
|
||||
|
||||
|
@ -64,7 +64,7 @@ export function deriver<Props extends {}>(
|
|||
ref,
|
||||
) {
|
||||
let observableArr = []
|
||||
const observables: Record<string, IDerivation<$IntentionalAny>> = {}
|
||||
const observables: Record<string, Prism<$IntentionalAny>> = {}
|
||||
const normalProps: Record<string, $IntentionalAny> = {
|
||||
ref,
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue