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 get from 'lodash-es/get'
|
||||||
import isPlainObject from 'lodash-es/isPlainObject'
|
import isPlainObject from 'lodash-es/isPlainObject'
|
||||||
import last from 'lodash-es/last'
|
import last from 'lodash-es/last'
|
||||||
import type {IDerivation} from './derivations/IDerivation'
|
import type {Prism} from './derivations/IDerivation'
|
||||||
import {isDerivation} from './derivations/IDerivation'
|
import {isDerivation} from './derivations/IDerivation'
|
||||||
import type {Pointer, PointerType} from './pointer'
|
import type {Pointer, PointerType} from './pointer'
|
||||||
import {isPointer} from './pointer'
|
import {isPointer} from './pointer'
|
||||||
|
@ -34,7 +34,7 @@ export interface IdentityDerivationProvider {
|
||||||
*
|
*
|
||||||
* @param path - The path to create the derivation at.
|
* @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 => {
|
const getTypeOfValue = (v: unknown): ValueTypes => {
|
||||||
|
@ -246,7 +246,7 @@ export default class Atom<State extends {}>
|
||||||
*
|
*
|
||||||
* @param path - The path to create the derivation at.
|
* @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) =>
|
const subscribe = (listener: (val: unknown) => void) =>
|
||||||
this._onPathValueChange(path, listener)
|
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
|
* 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>>(
|
export const valueDerivation = <P extends PointerType<$IntentionalAny>>(
|
||||||
pointer: P,
|
pointer: P,
|
||||||
): IDerivation<P extends PointerType<infer T> ? T : void> => {
|
): Prism<P extends PointerType<infer T> ? T : void> => {
|
||||||
const meta = getPointerMeta(pointer)
|
const meta = getPointerMeta(pointer)
|
||||||
|
|
||||||
let derivation = identityDerivationWeakMap.get(meta)
|
let derivation = identityDerivationWeakMap.get(meta)
|
||||||
|
@ -309,14 +309,14 @@ function isIdentityDerivationProvider(
|
||||||
export const val = <
|
export const val = <
|
||||||
P extends
|
P extends
|
||||||
| PointerType<$IntentionalAny>
|
| PointerType<$IntentionalAny>
|
||||||
| IDerivation<$IntentionalAny>
|
| Prism<$IntentionalAny>
|
||||||
| undefined
|
| undefined
|
||||||
| null,
|
| null,
|
||||||
>(
|
>(
|
||||||
input: P,
|
input: P,
|
||||||
): P extends PointerType<infer T>
|
): P extends PointerType<infer T>
|
||||||
? T
|
? T
|
||||||
: P extends IDerivation<infer T>
|
: P extends Prism<infer T>
|
||||||
? T
|
? T
|
||||||
: P extends undefined | null
|
: P extends undefined | null
|
||||||
? P
|
? P
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import type {IDerivation} from './derivations/IDerivation'
|
import type {Prism} from './derivations/IDerivation'
|
||||||
import prism from './derivations/prism/prism'
|
import prism from './derivations/prism/prism'
|
||||||
import Emitter from './utils/Emitter'
|
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.
|
* 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.
|
* reference even if the objects are structurally equal.
|
||||||
*/
|
*/
|
||||||
export default class Box<V> implements IBox<V> {
|
export default class Box<V> implements IBox<V> {
|
||||||
private _publicDerivation: IDerivation<V>
|
private _publicDerivation: Prism<V>
|
||||||
private _emitter = new Emitter<V>()
|
private _emitter = new Emitter<V>()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
import type Ticker from '../Ticker'
|
import type Ticker from '../Ticker'
|
||||||
import type {$IntentionalAny, VoidFn} from '../types'
|
import type {$IntentionalAny, VoidFn} from '../types'
|
||||||
|
|
||||||
type IDependent = (msgComingFrom: IDerivation<$IntentionalAny>) => void
|
type IDependent = (msgComingFrom: Prism<$IntentionalAny>) => void
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Common interface for derivations.
|
* Common interface for derivations.
|
||||||
*/
|
*/
|
||||||
export interface IDerivation<V> {
|
export interface Prism<V> {
|
||||||
/**
|
/**
|
||||||
* Whether the object is a derivation.
|
* Whether the object is a derivation.
|
||||||
*/
|
*/
|
||||||
|
@ -63,6 +63,6 @@ export interface IDerivation<V> {
|
||||||
/**
|
/**
|
||||||
* Returns whether `d` is a derivation.
|
* 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
|
return d && d.isDerivation && d.isDerivation === true
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
import {valueDerivation} from '../Atom'
|
import {valueDerivation} from '../Atom'
|
||||||
import type {Pointer} from '../pointer'
|
import type {Pointer} from '../pointer'
|
||||||
import {isPointer} from '../pointer'
|
import {isPointer} from '../pointer'
|
||||||
import type {IDerivation} from './IDerivation'
|
import type {Prism} from './IDerivation'
|
||||||
import {isDerivation} from './IDerivation'
|
import {isDerivation} from './IDerivation'
|
||||||
|
|
||||||
export default function* iterateAndCountTicks<V>(
|
export default function* iterateAndCountTicks<V>(
|
||||||
pointerOrDerivation: IDerivation<V> | Pointer<V>,
|
pointerOrDerivation: Prism<V> | Pointer<V>,
|
||||||
): Generator<{value: V; ticks: number}, void, void> {
|
): Generator<{value: V; ticks: number}, void, void> {
|
||||||
let d
|
let d
|
||||||
if (isPointer(pointerOrDerivation)) {
|
if (isPointer(pointerOrDerivation)) {
|
||||||
d = valueDerivation(pointerOrDerivation) as IDerivation<V>
|
d = valueDerivation(pointerOrDerivation) as Prism<V>
|
||||||
} else if (isDerivation(pointerOrDerivation)) {
|
} else if (isDerivation(pointerOrDerivation)) {
|
||||||
d = pointerOrDerivation
|
d = pointerOrDerivation
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -2,15 +2,15 @@ import {valueDerivation} from '../Atom'
|
||||||
import type {Pointer} from '../pointer'
|
import type {Pointer} from '../pointer'
|
||||||
import {isPointer} from '../pointer'
|
import {isPointer} from '../pointer'
|
||||||
import Ticker from '../Ticker'
|
import Ticker from '../Ticker'
|
||||||
import type {IDerivation} from './IDerivation'
|
import type {Prism} from './IDerivation'
|
||||||
import {isDerivation} from './IDerivation'
|
import {isDerivation} from './IDerivation'
|
||||||
|
|
||||||
export default function* iterateOver<V>(
|
export default function* iterateOver<V>(
|
||||||
pointerOrDerivation: IDerivation<V> | Pointer<V>,
|
pointerOrDerivation: Prism<V> | Pointer<V>,
|
||||||
): Generator<V, void, void> {
|
): Generator<V, void, void> {
|
||||||
let d
|
let d
|
||||||
if (isPointer(pointerOrDerivation)) {
|
if (isPointer(pointerOrDerivation)) {
|
||||||
d = valueDerivation(pointerOrDerivation) as IDerivation<V>
|
d = valueDerivation(pointerOrDerivation) as Prism<V>
|
||||||
} else if (isDerivation(pointerOrDerivation)) {
|
} else if (isDerivation(pointerOrDerivation)) {
|
||||||
d = pointerOrDerivation
|
d = pointerOrDerivation
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import type {$IntentionalAny} from '../../types'
|
import type {$IntentionalAny} from '../../types'
|
||||||
import Stack from '../../utils/Stack'
|
import Stack from '../../utils/Stack'
|
||||||
import type {IDerivation} from '../IDerivation'
|
import type {Prism} from '../IDerivation'
|
||||||
|
|
||||||
function createMechanism() {
|
function createMechanism() {
|
||||||
const noop = () => {}
|
const noop = () => {}
|
||||||
|
@ -8,7 +8,7 @@ function createMechanism() {
|
||||||
const stack = new Stack<Collector>()
|
const stack = new Stack<Collector>()
|
||||||
const noopCollector: Collector = noop
|
const noopCollector: Collector = noop
|
||||||
|
|
||||||
type Collector = (d: IDerivation<$IntentionalAny>) => void
|
type Collector = (d: Prism<$IntentionalAny>) => void
|
||||||
|
|
||||||
const pushCollector = (collector: Collector): void => {
|
const pushCollector = (collector: Collector): void => {
|
||||||
stack.push(collector)
|
stack.push(collector)
|
||||||
|
@ -36,7 +36,7 @@ function createMechanism() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const reportResolutionStart = (d: IDerivation<$IntentionalAny>) => {
|
const reportResolutionStart = (d: Prism<$IntentionalAny>) => {
|
||||||
const possibleCollector = stack.peek()
|
const possibleCollector = stack.peek()
|
||||||
if (possibleCollector) {
|
if (possibleCollector) {
|
||||||
possibleCollector(d)
|
possibleCollector(d)
|
||||||
|
@ -45,7 +45,7 @@ function createMechanism() {
|
||||||
stack.push(noopCollector)
|
stack.push(noopCollector)
|
||||||
}
|
}
|
||||||
|
|
||||||
const reportResolutionEnd = (_d: IDerivation<$IntentionalAny>) => {
|
const reportResolutionEnd = (_d: Prism<$IntentionalAny>) => {
|
||||||
stack.pop()
|
stack.pop()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import type Ticker from '../../Ticker'
|
import type Ticker from '../../Ticker'
|
||||||
import type {$IntentionalAny, VoidFn} from '../../types'
|
import type {$IntentionalAny, VoidFn} from '../../types'
|
||||||
import Stack from '../../utils/Stack'
|
import Stack from '../../utils/Stack'
|
||||||
import type {IDerivation} from '../IDerivation'
|
import type {Prism} from '../IDerivation'
|
||||||
import {isDerivation} from '../IDerivation'
|
import {isDerivation} from '../IDerivation'
|
||||||
import {
|
import {
|
||||||
startIgnoringDependencies,
|
startIgnoringDependencies,
|
||||||
|
@ -12,15 +12,14 @@ import {
|
||||||
reportResolutionEnd,
|
reportResolutionEnd,
|
||||||
} from './discoveryMechanism'
|
} from './discoveryMechanism'
|
||||||
|
|
||||||
type IDependent = (msgComingFrom: IDerivation<$IntentionalAny>) => void
|
type IDependent = (msgComingFrom: Prism<$IntentionalAny>) => void
|
||||||
|
|
||||||
const voidFn = () => {}
|
const voidFn = () => {}
|
||||||
|
|
||||||
class HotHandle<V> {
|
class HotHandle<V> {
|
||||||
private _didMarkDependentsAsStale: boolean = false
|
private _didMarkDependentsAsStale: boolean = false
|
||||||
private _isFresh: boolean = false
|
private _isFresh: boolean = false
|
||||||
protected _cacheOfDendencyValues: Map<IDerivation<unknown>, unknown> =
|
protected _cacheOfDendencyValues: Map<Prism<unknown>, unknown> = new Map()
|
||||||
new Map()
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
|
@ -30,9 +29,9 @@ class HotHandle<V> {
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @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(
|
private _scope: HotScope = new HotScope(
|
||||||
this as $IntentionalAny as HotHandle<unknown>,
|
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()
|
this._cacheOfDendencyValues.clear()
|
||||||
|
|
||||||
const collector = (observedDep: IDerivation<unknown>): void => {
|
const collector = (observedDep: Prism<unknown>): void => {
|
||||||
newDeps.add(observedDep)
|
newDeps.add(observedDep)
|
||||||
this._addDependency(observedDep)
|
this._addDependency(observedDep)
|
||||||
}
|
}
|
||||||
|
@ -161,9 +160,7 @@ class HotHandle<V> {
|
||||||
this._markAsStale()
|
this._markAsStale()
|
||||||
}
|
}
|
||||||
|
|
||||||
protected _reactToDependencyGoingStale = (
|
protected _reactToDependencyGoingStale = (which: Prism<$IntentionalAny>) => {
|
||||||
which: IDerivation<$IntentionalAny>,
|
|
||||||
) => {
|
|
||||||
this._possiblyStaleDeps.add(which)
|
this._possiblyStaleDeps.add(which)
|
||||||
|
|
||||||
this._markAsStale()
|
this._markAsStale()
|
||||||
|
@ -183,7 +180,7 @@ class HotHandle<V> {
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
protected _addDependency(d: IDerivation<$IntentionalAny>) {
|
protected _addDependency(d: Prism<$IntentionalAny>) {
|
||||||
if (this._dependencies.has(d)) return
|
if (this._dependencies.has(d)) return
|
||||||
this._dependencies.add(d)
|
this._dependencies.add(d)
|
||||||
d._addDependent(this._reactToDependencyGoingStale)
|
d._addDependent(this._reactToDependencyGoingStale)
|
||||||
|
@ -192,7 +189,7 @@ class HotHandle<V> {
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
protected _removeDependency(d: IDerivation<$IntentionalAny>) {
|
protected _removeDependency(d: Prism<$IntentionalAny>) {
|
||||||
if (!this._dependencies.has(d)) return
|
if (!this._dependencies.has(d)) return
|
||||||
this._dependencies.delete(d)
|
this._dependencies.delete(d)
|
||||||
d._removeDependent(this._reactToDependencyGoingStale)
|
d._removeDependent(this._reactToDependencyGoingStale)
|
||||||
|
@ -201,7 +198,7 @@ class HotHandle<V> {
|
||||||
|
|
||||||
const emptyObject = {}
|
const emptyObject = {}
|
||||||
|
|
||||||
class PrismDerivation<V> implements IDerivation<V> {
|
class PrismDerivation<V> implements Prism<V> {
|
||||||
/**
|
/**
|
||||||
* Whether the object is a derivation.
|
* Whether the object is a derivation.
|
||||||
*/
|
*/
|
||||||
|
@ -703,11 +700,9 @@ function inPrism(): boolean {
|
||||||
return !!hookScopeStack.peek()
|
return !!hookScopeStack.peek()
|
||||||
}
|
}
|
||||||
|
|
||||||
const possibleDerivationToValue = <
|
const possibleDerivationToValue = <P extends Prism<$IntentionalAny> | unknown>(
|
||||||
P extends IDerivation<$IntentionalAny> | unknown,
|
|
||||||
>(
|
|
||||||
input: P,
|
input: P,
|
||||||
): P extends IDerivation<infer T> ? T : P => {
|
): P extends Prism<infer T> ? T : P => {
|
||||||
if (isDerivation(input)) {
|
if (isDerivation(input)) {
|
||||||
return input.getValue() as $IntentionalAny
|
return input.getValue() as $IntentionalAny
|
||||||
} else {
|
} else {
|
||||||
|
@ -728,7 +723,7 @@ function source<V>(
|
||||||
}
|
}
|
||||||
|
|
||||||
type IPrismFn = {
|
type IPrismFn = {
|
||||||
<T>(fn: () => T): IDerivation<T>
|
<T>(fn: () => T): Prism<T>
|
||||||
ref: typeof ref
|
ref: typeof ref
|
||||||
effect: typeof effect
|
effect: typeof effect
|
||||||
memo: typeof memo
|
memo: typeof memo
|
||||||
|
|
|
@ -9,7 +9,7 @@ export {default as Atom, val, valueDerivation} from './Atom'
|
||||||
export {default as Box} from './Box'
|
export {default as Box} from './Box'
|
||||||
export type {IBox} from './Box'
|
export type {IBox} from './Box'
|
||||||
export {isDerivation} from './derivations/IDerivation'
|
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 iterateAndCountTicks} from './derivations/iterateAndCountTicks'
|
||||||
export {default as iterateOver} from './derivations/iterateOver'
|
export {default as iterateOver} from './derivations/iterateOver'
|
||||||
export {default as prism} from './derivations/prism/prism'
|
export {default as prism} from './derivations/prism/prism'
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
* @packageDocumentation
|
* @packageDocumentation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import type {IDerivation} from '@theatre/dataverse'
|
import type {Prism} from '@theatre/dataverse'
|
||||||
import {Box} from '@theatre/dataverse'
|
import {Box} from '@theatre/dataverse'
|
||||||
import {prism, val} from '@theatre/dataverse'
|
import {prism, val} from '@theatre/dataverse'
|
||||||
import {findIndex} from 'lodash-es'
|
import {findIndex} from 'lodash-es'
|
||||||
|
@ -144,7 +144,7 @@ type QueueItem<T = unknown> = {
|
||||||
/**
|
/**
|
||||||
* A reference to the derivation
|
* A reference to the derivation
|
||||||
*/
|
*/
|
||||||
der: IDerivation<T>
|
der: Prism<T>
|
||||||
/**
|
/**
|
||||||
* The last value of this derivation.
|
* 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
|
* 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.
|
* `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 _forceUpdate = useForceUpdate(debugLabel)
|
||||||
|
|
||||||
const ref = useRef<QueueItem<T>>(undefined as $IntentionalAny)
|
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>(
|
export function usePrismWithoutReRender<T>(
|
||||||
fn: () => T,
|
fn: () => T,
|
||||||
deps: unknown[],
|
deps: unknown[],
|
||||||
): IDerivation<T> {
|
): Prism<T> {
|
||||||
const derivation = useMemo(() => prism(fn), deps)
|
const derivation = useMemo(() => prism(fn), deps)
|
||||||
|
|
||||||
return useDerivationWithoutReRender(derivation)
|
return useDerivationWithoutReRender(derivation)
|
||||||
|
@ -398,9 +398,7 @@ export function usePrismWithoutReRender<T>(
|
||||||
* return the value of the derivation, and it does not
|
* return the value of the derivation, and it does not
|
||||||
* re-render the component if the value of the derivation changes.
|
* re-render the component if the value of the derivation changes.
|
||||||
*/
|
*/
|
||||||
export function useDerivationWithoutReRender<T>(
|
export function useDerivationWithoutReRender<T>(der: Prism<T>): Prism<T> {
|
||||||
der: IDerivation<T>,
|
|
||||||
): IDerivation<T> {
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const untap = der.keepHot()
|
const untap = der.keepHot()
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ import globals from '@theatre/shared/globals'
|
||||||
/**
|
/**
|
||||||
* @remarks
|
* @remarks
|
||||||
* TODO this could be turned into a simple derivation, like:
|
* 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(
|
export default async function initialiseProjectState(
|
||||||
studio: Studio,
|
studio: Studio,
|
||||||
|
|
|
@ -3,7 +3,7 @@ import type Sheet from '@theatre/core/sheets/Sheet'
|
||||||
import type {SequenceAddress} from '@theatre/shared/utils/addresses'
|
import type {SequenceAddress} from '@theatre/shared/utils/addresses'
|
||||||
import didYouMean from '@theatre/shared/utils/didYouMean'
|
import didYouMean from '@theatre/shared/utils/didYouMean'
|
||||||
import {InvalidArgumentError} from '@theatre/shared/utils/errors'
|
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 {pointer} from '@theatre/dataverse'
|
||||||
import {Box, prism, val} from '@theatre/dataverse'
|
import {Box, prism, val} from '@theatre/dataverse'
|
||||||
import {padStart} from 'lodash-es'
|
import {padStart} from 'lodash-es'
|
||||||
|
@ -38,10 +38,10 @@ export default class Sequence {
|
||||||
publicApi: TheatreSequence
|
publicApi: TheatreSequence
|
||||||
|
|
||||||
private _playbackControllerBox: IBox<IPlaybackController>
|
private _playbackControllerBox: IBox<IPlaybackController>
|
||||||
private _statePointerDerivation: IDerivation<Pointer<IPlaybackState>>
|
private _statePointerDerivation: Prism<Pointer<IPlaybackState>>
|
||||||
private _positionD: IDerivation<number>
|
private _positionD: Prism<number>
|
||||||
private _positionFormatterD: IDerivation<ISequencePositionFormatter>
|
private _positionFormatterD: Prism<ISequencePositionFormatter>
|
||||||
_playableRangeD: undefined | IDerivation<{start: number; end: number}>
|
_playableRangeD: undefined | Prism<{start: number; end: number}>
|
||||||
|
|
||||||
readonly pointer: ISequence['pointer'] = pointer({root: this, path: []})
|
readonly pointer: ISequence['pointer'] = pointer({root: this, path: []})
|
||||||
readonly $$isIdentityDerivationProvider = true
|
readonly $$isIdentityDerivationProvider = true
|
||||||
|
@ -50,8 +50,8 @@ export default class Sequence {
|
||||||
constructor(
|
constructor(
|
||||||
readonly _project: Project,
|
readonly _project: Project,
|
||||||
readonly _sheet: Sheet,
|
readonly _sheet: Sheet,
|
||||||
readonly _lengthD: IDerivation<number>,
|
readonly _lengthD: Prism<number>,
|
||||||
readonly _subUnitsPerUnitD: IDerivation<number>,
|
readonly _subUnitsPerUnitD: Prism<number>,
|
||||||
playbackController?: IPlaybackController,
|
playbackController?: IPlaybackController,
|
||||||
) {
|
) {
|
||||||
this._logger = _project._logger
|
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) {
|
if (path.length === 0) {
|
||||||
return prism((): ISequence['pointer']['$$__pointer_type'] => ({
|
return prism((): ISequence['pointer']['$$__pointer_type'] => ({
|
||||||
length: val(this.pointer.length),
|
length: val(this.pointer.length),
|
||||||
|
@ -177,7 +177,7 @@ export default class Sequence {
|
||||||
return val(this._playbackControllerBox.get().statePointer.playing)
|
return val(this._playbackControllerBox.get().statePointer.playing)
|
||||||
}
|
}
|
||||||
|
|
||||||
_makeRangeFromSequenceTemplate(): IDerivation<IPlaybackRange> {
|
_makeRangeFromSequenceTemplate(): Prism<IPlaybackRange> {
|
||||||
return prism(() => {
|
return prism(() => {
|
||||||
return [0, val(this._lengthD)]
|
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
|
* @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)
|
return this._playbackControllerBox.get().playDynamicRange(rangeD)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ import type {
|
||||||
Keyframe,
|
Keyframe,
|
||||||
TrackData,
|
TrackData,
|
||||||
} from '@theatre/core/projects/store/types/SheetState_Historic'
|
} 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 {prism, val} from '@theatre/dataverse'
|
||||||
import type {IUtilContext} from '@theatre/shared/logger'
|
import type {IUtilContext} from '@theatre/shared/logger'
|
||||||
import type {SerializableValue} from '@theatre/shared/utils/types'
|
import type {SerializableValue} from '@theatre/shared/utils/types'
|
||||||
|
@ -28,8 +28,8 @@ export type InterpolationTriple = {
|
||||||
export default function interpolationTripleAtPosition(
|
export default function interpolationTripleAtPosition(
|
||||||
ctx: IUtilContext,
|
ctx: IUtilContext,
|
||||||
trackP: Pointer<TrackData | undefined>,
|
trackP: Pointer<TrackData | undefined>,
|
||||||
timeD: IDerivation<number>,
|
timeD: Prism<number>,
|
||||||
): IDerivation<InterpolationTriple | undefined> {
|
): Prism<InterpolationTriple | undefined> {
|
||||||
return prism(() => {
|
return prism(() => {
|
||||||
const track = val(trackP)
|
const track = val(trackP)
|
||||||
const driverD = prism.memo(
|
const driverD = prism.memo(
|
||||||
|
@ -55,7 +55,7 @@ type IStartedState = {
|
||||||
started: true
|
started: true
|
||||||
validFrom: number
|
validFrom: number
|
||||||
validTo: number
|
validTo: number
|
||||||
der: IDerivation<InterpolationTriple | undefined>
|
der: Prism<InterpolationTriple | undefined>
|
||||||
}
|
}
|
||||||
|
|
||||||
type IState = {started: false} | IStartedState
|
type IState = {started: false} | IStartedState
|
||||||
|
@ -63,8 +63,8 @@ type IState = {started: false} | IStartedState
|
||||||
function _forKeyframedTrack(
|
function _forKeyframedTrack(
|
||||||
ctx: IUtilContext,
|
ctx: IUtilContext,
|
||||||
track: BasicKeyframedTrack,
|
track: BasicKeyframedTrack,
|
||||||
timeD: IDerivation<number>,
|
timeD: Prism<number>,
|
||||||
): IDerivation<InterpolationTriple | undefined> {
|
): Prism<InterpolationTriple | undefined> {
|
||||||
return prism(() => {
|
return prism(() => {
|
||||||
let stateRef = prism.ref<IState>('state', {started: false})
|
let stateRef = prism.ref<IState>('state', {started: false})
|
||||||
let state = stateRef.current
|
let state = stateRef.current
|
||||||
|
@ -83,7 +83,7 @@ const undefinedConstD = prism(() => undefined)
|
||||||
|
|
||||||
function updateState(
|
function updateState(
|
||||||
ctx: IUtilContext,
|
ctx: IUtilContext,
|
||||||
progressionD: IDerivation<number>,
|
progressionD: Prism<number>,
|
||||||
track: BasicKeyframedTrack,
|
track: BasicKeyframedTrack,
|
||||||
): IStartedState {
|
): IStartedState {
|
||||||
const progression = progressionD.getValue()
|
const progression = progressionD.getValue()
|
||||||
|
@ -173,7 +173,7 @@ const states = {
|
||||||
between(
|
between(
|
||||||
left: Keyframe,
|
left: Keyframe,
|
||||||
right: Keyframe,
|
right: Keyframe,
|
||||||
progressionD: IDerivation<number>,
|
progressionD: Prism<number>,
|
||||||
): IStartedState {
|
): IStartedState {
|
||||||
if (!left.connectedRight) {
|
if (!left.connectedRight) {
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -5,7 +5,7 @@ import type {
|
||||||
import {defer} from '@theatre/shared/utils/defer'
|
import {defer} from '@theatre/shared/utils/defer'
|
||||||
import {InvalidArgumentError} from '@theatre/shared/utils/errors'
|
import {InvalidArgumentError} from '@theatre/shared/utils/errors'
|
||||||
import noop from '@theatre/shared/utils/noop'
|
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 {Atom} from '@theatre/dataverse'
|
||||||
import type {
|
import type {
|
||||||
IPlaybackController,
|
IPlaybackController,
|
||||||
|
@ -34,7 +34,7 @@ export default class AudioPlaybackController implements IPlaybackController {
|
||||||
this._mainGain.connect(this._nodeDestination)
|
this._mainGain.connect(this._nodeDestination)
|
||||||
}
|
}
|
||||||
|
|
||||||
playDynamicRange(rangeD: IDerivation<IPlaybackRange>): Promise<unknown> {
|
playDynamicRange(rangeD: Prism<IPlaybackRange>): Promise<unknown> {
|
||||||
const deferred = defer<boolean>()
|
const deferred = defer<boolean>()
|
||||||
if (this._playing) this.pause()
|
if (this._playing) this.pause()
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ import type {
|
||||||
} from '@theatre/core/sequences/Sequence'
|
} from '@theatre/core/sequences/Sequence'
|
||||||
import {defer} from '@theatre/shared/utils/defer'
|
import {defer} from '@theatre/shared/utils/defer'
|
||||||
import noop from '@theatre/shared/utils/noop'
|
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 {Atom} from '@theatre/dataverse'
|
||||||
|
|
||||||
export interface IPlaybackState {
|
export interface IPlaybackState {
|
||||||
|
@ -36,7 +36,7 @@ export interface IPlaybackController {
|
||||||
* @returns a promise that gets rejected if the playback stopped for whatever reason
|
* @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
|
pause(): void
|
||||||
}
|
}
|
||||||
|
@ -203,7 +203,7 @@ export default class DefaultPlaybackController implements IPlaybackController {
|
||||||
return deferred.promise
|
return deferred.promise
|
||||||
}
|
}
|
||||||
|
|
||||||
playDynamicRange(rangeD: IDerivation<IPlaybackRange>): Promise<unknown> {
|
playDynamicRange(rangeD: Prism<IPlaybackRange>): Promise<unknown> {
|
||||||
if (this.playing) {
|
if (this.playing) {
|
||||||
this.pause()
|
this.pause()
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ import type {
|
||||||
import {valToAtom} from '@theatre/shared/utils/valToAtom'
|
import {valToAtom} from '@theatre/shared/utils/valToAtom'
|
||||||
import type {
|
import type {
|
||||||
IdentityDerivationProvider,
|
IdentityDerivationProvider,
|
||||||
IDerivation,
|
Prism,
|
||||||
Pointer,
|
Pointer,
|
||||||
} from '@theatre/dataverse'
|
} from '@theatre/dataverse'
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ export default class SheetObject implements IdentityDerivationProvider {
|
||||||
this.publicApi = new TheatreSheetObject(this)
|
this.publicApi = new TheatreSheetObject(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
getValues(): IDerivation<Pointer<SheetObjectPropsValue>> {
|
getValues(): Prism<Pointer<SheetObjectPropsValue>> {
|
||||||
// Cache the derivation because only one is needed per SheetObject.
|
// Cache the derivation because only one is needed per SheetObject.
|
||||||
// Also, if `onValuesChange()` is unsubscribed from, this derivation will go cold
|
// 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.
|
// 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
|
) as SerializableValue as T
|
||||||
}
|
}
|
||||||
|
|
||||||
getIdentityDerivation(path: Array<string | number>): IDerivation<unknown> {
|
getIdentityDerivation(path: Array<string | number>): Prism<unknown> {
|
||||||
/**
|
/**
|
||||||
* @remarks
|
* @remarks
|
||||||
* TODO perf: Too much indirection here.
|
* TODO perf: Too much indirection here.
|
||||||
|
@ -229,7 +229,7 @@ export default class SheetObject implements IdentityDerivationProvider {
|
||||||
/**
|
/**
|
||||||
* Returns values of props that are sequenced.
|
* Returns values of props that are sequenced.
|
||||||
*/
|
*/
|
||||||
getSequencedValues(): IDerivation<Pointer<SheetObjectPropsValue>> {
|
getSequencedValues(): Prism<Pointer<SheetObjectPropsValue>> {
|
||||||
return prism(() => {
|
return prism(() => {
|
||||||
const tracksToProcessD = prism.memo(
|
const tracksToProcessD = prism.memo(
|
||||||
'tracksToProcess',
|
'tracksToProcess',
|
||||||
|
@ -305,7 +305,7 @@ export default class SheetObject implements IdentityDerivationProvider {
|
||||||
|
|
||||||
protected _trackIdToDerivation(
|
protected _trackIdToDerivation(
|
||||||
trackId: SequenceTrackId,
|
trackId: SequenceTrackId,
|
||||||
): IDerivation<InterpolationTriple | undefined> {
|
): Prism<InterpolationTriple | undefined> {
|
||||||
const trackP =
|
const trackP =
|
||||||
this.template.project.pointers.historic.sheetsById[this.address.sheetId]
|
this.template.project.pointers.historic.sheetsById[this.address.sheetId]
|
||||||
.sequence.tracksByObject[this.address.objectKey].trackData[trackId]
|
.sequence.tracksByObject[this.address.objectKey].trackData[trackId]
|
||||||
|
|
|
@ -21,7 +21,7 @@ import type {
|
||||||
SerializableMap,
|
SerializableMap,
|
||||||
SerializableValue,
|
SerializableValue,
|
||||||
} from '@theatre/shared/utils/types'
|
} 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 {Atom, getPointerParts, prism, val} from '@theatre/dataverse'
|
||||||
import set from 'lodash-es/set'
|
import set from 'lodash-es/set'
|
||||||
import getPropDefaultsOfSheetObject from './getPropDefaultsOfSheetObject'
|
import getPropDefaultsOfSheetObject from './getPropDefaultsOfSheetObject'
|
||||||
|
@ -115,7 +115,7 @@ export default class SheetObjectTemplate {
|
||||||
/**
|
/**
|
||||||
* Returns the default values (all defaults are read from the config)
|
* Returns the default values (all defaults are read from the config)
|
||||||
*/
|
*/
|
||||||
getDefaultValues(): IDerivation<SerializableMap> {
|
getDefaultValues(): Prism<SerializableMap> {
|
||||||
return this._cache.get('getDefaultValues()', () =>
|
return this._cache.get('getDefaultValues()', () =>
|
||||||
prism(() => {
|
prism(() => {
|
||||||
const config = val(this.configPointer)
|
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)
|
* Returns values that are set statically (ie, not sequenced, and not defaults)
|
||||||
*/
|
*/
|
||||||
getStaticValues(): IDerivation<SerializableMap> {
|
getStaticValues(): Prism<SerializableMap> {
|
||||||
return this._cache.get('getDerivationOfStatics', () =>
|
return this._cache.get('getDerivationOfStatics', () =>
|
||||||
prism(() => {
|
prism(() => {
|
||||||
const pointerToSheetState =
|
const pointerToSheetState =
|
||||||
|
@ -155,7 +155,7 @@ export default class SheetObjectTemplate {
|
||||||
*
|
*
|
||||||
* Returns an array.
|
* Returns an array.
|
||||||
*/
|
*/
|
||||||
getArrayOfValidSequenceTracks(): IDerivation<
|
getArrayOfValidSequenceTracks(): Prism<
|
||||||
Array<{pathToProp: PathToProp; trackId: SequenceTrackId}>
|
Array<{pathToProp: PathToProp; trackId: SequenceTrackId}>
|
||||||
> {
|
> {
|
||||||
return this._cache.get('getArrayOfValidSequenceTracks', () =>
|
return this._cache.get('getArrayOfValidSequenceTracks', () =>
|
||||||
|
@ -226,7 +226,7 @@ export default class SheetObjectTemplate {
|
||||||
*
|
*
|
||||||
* Not available in core.
|
* Not available in core.
|
||||||
*/
|
*/
|
||||||
getMapOfValidSequenceTracks_forStudio(): IDerivation<IPropPathToTrackIdTree> {
|
getMapOfValidSequenceTracks_forStudio(): Prism<IPropPathToTrackIdTree> {
|
||||||
return this._cache.get('getMapOfValidSequenceTracks_forStudio', () =>
|
return this._cache.get('getMapOfValidSequenceTracks_forStudio', () =>
|
||||||
prism(() => {
|
prism(() => {
|
||||||
const arr = val(this.getArrayOfValidSequenceTracks())
|
const arr = val(this.getArrayOfValidSequenceTracks())
|
||||||
|
|
|
@ -9,7 +9,7 @@ import type {
|
||||||
DeepPartialOfSerializableValue,
|
DeepPartialOfSerializableValue,
|
||||||
VoidFn,
|
VoidFn,
|
||||||
} from '@theatre/shared/utils/types'
|
} 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 {prism, val} from '@theatre/dataverse'
|
||||||
import type SheetObject from './SheetObject'
|
import type SheetObject from './SheetObject'
|
||||||
import type {
|
import type {
|
||||||
|
@ -147,10 +147,10 @@ export default class TheatreSheetObject<
|
||||||
return {...privateAPI(this).address}
|
return {...privateAPI(this).address}
|
||||||
}
|
}
|
||||||
|
|
||||||
private _valuesDerivation(): IDerivation<this['value']> {
|
private _valuesDerivation(): Prism<this['value']> {
|
||||||
return this._cache.get('onValuesChangeDerivation', () => {
|
return this._cache.get('onValuesChangeDerivation', () => {
|
||||||
const sheetObject = privateAPI(this)
|
const sheetObject = privateAPI(this)
|
||||||
const d: IDerivation<PropsValue<Props>> = prism(() => {
|
const d: Prism<PropsValue<Props>> = prism(() => {
|
||||||
return val(sheetObject.getValues().getValue()) as $FixMe
|
return val(sheetObject.getValues().getValue()) as $FixMe
|
||||||
})
|
})
|
||||||
return d
|
return d
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import type {IProject, ISheet, ISheetObject} from '@theatre/core'
|
import type {IProject, ISheet, ISheetObject} from '@theatre/core'
|
||||||
import studioTicker from '@theatre/studio/studioTicker'
|
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 {prism} from '@theatre/dataverse'
|
||||||
import SimpleCache from '@theatre/shared/utils/SimpleCache'
|
import SimpleCache from '@theatre/shared/utils/SimpleCache'
|
||||||
import type {$IntentionalAny, VoidFn} from '@theatre/shared/utils/types'
|
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()', () =>
|
return this._cache.get('_getStateDerivation()', () =>
|
||||||
prism((): (ISheetObject | ISheet)[] => {
|
prism((): (ISheetObject | ISheet)[] => {
|
||||||
return getOutlineSelection()
|
return getOutlineSelection()
|
||||||
|
|
|
@ -3,7 +3,7 @@ import getStudio from '@theatre/studio/getStudio'
|
||||||
import {cmdIsDown} from '@theatre/studio/utils/keyboardUtils'
|
import {cmdIsDown} from '@theatre/studio/utils/keyboardUtils'
|
||||||
import {getSelectedSequence} from '@theatre/studio/selectors'
|
import {getSelectedSequence} from '@theatre/studio/selectors'
|
||||||
import type {$IntentionalAny} from '@theatre/shared/utils/types'
|
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 {Box, prism, val} from '@theatre/dataverse'
|
||||||
import type {IPlaybackRange} from '@theatre/core/sequences/Sequence'
|
import type {IPlaybackRange} from '@theatre/core/sequences/Sequence'
|
||||||
import type Sequence from '@theatre/core/sequences/Sequence'
|
import type Sequence from '@theatre/core/sequences/Sequence'
|
||||||
|
@ -151,7 +151,7 @@ export default function useKeyboardShortcuts() {
|
||||||
}
|
}
|
||||||
|
|
||||||
type ControlledPlaybackStateBox = Box<
|
type ControlledPlaybackStateBox = Box<
|
||||||
undefined | IDerivation<{range: IPlaybackRange; isFollowingARange: boolean}>
|
undefined | Prism<{range: IPlaybackRange; isFollowingARange: boolean}>
|
||||||
>
|
>
|
||||||
|
|
||||||
const getPlaybackStateBox = memoizeFn(
|
const getPlaybackStateBox = memoizeFn(
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import type * as propTypes from '@theatre/core/propTypes'
|
import type * as propTypes from '@theatre/core/propTypes'
|
||||||
import {getPointerParts} from '@theatre/dataverse'
|
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 useContextMenu from '@theatre/studio/uiComponents/simpleContextMenu/useContextMenu'
|
||||||
import useRefAndState from '@theatre/studio/utils/useRefAndState'
|
import useRefAndState from '@theatre/studio/utils/useRefAndState'
|
||||||
import {last} from 'lodash-es'
|
import {last} from 'lodash-es'
|
||||||
|
@ -92,7 +92,7 @@ type ISingleRowPropEditorProps<T> = {
|
||||||
propConfig: propTypes.PropTypeConfig
|
propConfig: propTypes.PropTypeConfig
|
||||||
pointerToProp: Pointer<T>
|
pointerToProp: Pointer<T>
|
||||||
editingTools: ReturnType<typeof useEditingToolsForSimplePropInDetailsPanel>
|
editingTools: ReturnType<typeof useEditingToolsForSimplePropInDetailsPanel>
|
||||||
isPropHighlightedD: IDerivation<PropHighlighted>
|
isPropHighlightedD: Prism<PropHighlighted>
|
||||||
}
|
}
|
||||||
|
|
||||||
export function SingleRowPropEditor<T>({
|
export function SingleRowPropEditor<T>({
|
||||||
|
|
|
@ -8,7 +8,7 @@ import type {
|
||||||
SequenceEditorTree_SheetObject,
|
SequenceEditorTree_SheetObject,
|
||||||
} from '@theatre/studio/panels/SequenceEditorPanel/layout/tree'
|
} from '@theatre/studio/panels/SequenceEditorPanel/layout/tree'
|
||||||
import {usePrism, useVal} from '@theatre/react'
|
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 {prism, val, valueDerivation} from '@theatre/dataverse'
|
||||||
import React, {useMemo, Fragment} from 'react'
|
import React, {useMemo, Fragment} from 'react'
|
||||||
import styled from 'styled-components'
|
import styled from 'styled-components'
|
||||||
|
@ -230,7 +230,7 @@ function useCollectedSelectedPositions(
|
||||||
function collectedSelectedPositions(
|
function collectedSelectedPositions(
|
||||||
layoutP: Pointer<SequenceEditorPanelLayout>,
|
layoutP: Pointer<SequenceEditorPanelLayout>,
|
||||||
aggregatedKeyframes: AggregatedKeyframes,
|
aggregatedKeyframes: AggregatedKeyframes,
|
||||||
): IDerivation<_AggSelection> {
|
): Prism<_AggSelection> {
|
||||||
return prism(() => {
|
return prism(() => {
|
||||||
const selectionAtom = val(layoutP.selectionAtom)
|
const selectionAtom = val(layoutP.selectionAtom)
|
||||||
const selection = val(selectionAtom.pointer.current)
|
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 {prism, val} from '@theatre/dataverse'
|
||||||
import type {
|
import type {
|
||||||
KeyframeId,
|
KeyframeId,
|
||||||
|
@ -53,7 +53,7 @@ export function selectedKeyframeConnections(
|
||||||
projectId: ProjectId,
|
projectId: ProjectId,
|
||||||
sheetId: SheetId,
|
sheetId: SheetId,
|
||||||
selection: DopeSheetSelection | undefined,
|
selection: DopeSheetSelection | undefined,
|
||||||
): IDerivation<Array<KeyframeConnectionWithAddress>> {
|
): Prism<Array<KeyframeConnectionWithAddress>> {
|
||||||
return prism(() => {
|
return prism(() => {
|
||||||
if (selection === undefined) return []
|
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 {Atom, prism, val} from '@theatre/dataverse'
|
||||||
import mousePositionD from '@theatre/studio/utils/mousePositionD'
|
import mousePositionD from '@theatre/studio/utils/mousePositionD'
|
||||||
import type {$IntentionalAny} from '@theatre/shared/utils/types'
|
import type {$IntentionalAny} from '@theatre/shared/utils/types'
|
||||||
|
@ -26,7 +26,7 @@ export enum FrameStampPositionType {
|
||||||
}
|
}
|
||||||
|
|
||||||
const context = createContext<{
|
const context = createContext<{
|
||||||
currentD: IDerivation<[pos: number, posType: FrameStampPositionType]>
|
currentD: Prism<[pos: number, posType: FrameStampPositionType]>
|
||||||
getLock(): FrameStampPositionLock
|
getLock(): FrameStampPositionLock
|
||||||
}>(null as $IntentionalAny)
|
}>(null as $IntentionalAny)
|
||||||
|
|
||||||
|
@ -211,7 +211,7 @@ const ATTR_LOCK_FRAMESTAMP = 'data-theatre-lock-framestamp-to'
|
||||||
|
|
||||||
const pointerPositionInUnitSpace = (
|
const pointerPositionInUnitSpace = (
|
||||||
layoutP: Pointer<SequenceEditorPanelLayout>,
|
layoutP: Pointer<SequenceEditorPanelLayout>,
|
||||||
): IDerivation<[pos: number, posType: FrameStampPositionType]> => {
|
): Prism<[pos: number, posType: FrameStampPositionType]> => {
|
||||||
return prism(() => {
|
return prism(() => {
|
||||||
const rightDims = val(layoutP.rightDims)
|
const rightDims = val(layoutP.rightDims)
|
||||||
const clippedSpaceToUnitSpace = val(layoutP.clippedSpace.toUnitSpace)
|
const clippedSpaceToUnitSpace = val(layoutP.clippedSpace.toUnitSpace)
|
||||||
|
|
|
@ -9,7 +9,7 @@ import type {
|
||||||
StrictRecord,
|
StrictRecord,
|
||||||
} from '@theatre/shared/utils/types'
|
} from '@theatre/shared/utils/types'
|
||||||
import {valToAtom} from '@theatre/shared/utils/valToAtom'
|
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 {Atom, prism, val} from '@theatre/dataverse'
|
||||||
import type {SequenceEditorTree} from './tree'
|
import type {SequenceEditorTree} from './tree'
|
||||||
import {calculateSequenceEditorTree} from './tree'
|
import {calculateSequenceEditorTree} from './tree'
|
||||||
|
@ -176,7 +176,7 @@ const initialClippedSpaceRange: IRange = {start: 0, end: 10}
|
||||||
export function sequenceEditorPanelLayout(
|
export function sequenceEditorPanelLayout(
|
||||||
sheet: Sheet,
|
sheet: Sheet,
|
||||||
panelDimsP: Pointer<PanelDims>,
|
panelDimsP: Pointer<PanelDims>,
|
||||||
): IDerivation<Pointer<SequenceEditorPanelLayout>> {
|
): Prism<Pointer<SequenceEditorPanelLayout>> {
|
||||||
const studio = getStudio()!
|
const studio = getStudio()!
|
||||||
|
|
||||||
const ahistoricStateP =
|
const ahistoricStateP =
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import type {IDerivation} from '@theatre/dataverse'
|
import type {Prism} from '@theatre/dataverse'
|
||||||
import {val} from '@theatre/dataverse'
|
import {val} from '@theatre/dataverse'
|
||||||
import {Atom} from '@theatre/dataverse'
|
import {Atom} from '@theatre/dataverse'
|
||||||
import {prism} from '@theatre/dataverse'
|
import {prism} from '@theatre/dataverse'
|
||||||
|
@ -57,7 +57,7 @@ function createWhatPropIsHighlightedState() {
|
||||||
},
|
},
|
||||||
getIsPropHighlightedD(
|
getIsPropHighlightedD(
|
||||||
address: WithoutSheetInstance<PropAddress>,
|
address: WithoutSheetInstance<PropAddress>,
|
||||||
): IDerivation<PropHighlighted> {
|
): Prism<PropHighlighted> {
|
||||||
const highlightedP = pointerDeep(
|
const highlightedP = pointerDeep(
|
||||||
whatIsHighlighted.pointer.deepPath,
|
whatIsHighlighted.pointer.deepPath,
|
||||||
addressToArray(address),
|
addressToArray(address),
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import get from 'lodash-es/get'
|
import get from 'lodash-es/get'
|
||||||
import React from 'react'
|
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 {getPointerParts, prism, val} from '@theatre/dataverse'
|
||||||
import type SheetObject from '@theatre/core/sheetObjects/SheetObject'
|
import type SheetObject from '@theatre/core/sheetObjects/SheetObject'
|
||||||
import getStudio from '@theatre/studio/getStudio'
|
import getStudio from '@theatre/studio/getStudio'
|
||||||
|
@ -59,7 +59,7 @@ type EditingTools<T> =
|
||||||
| EditingToolsStatic<T>
|
| EditingToolsStatic<T>
|
||||||
| EditingToolsSequenced<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`,
|
* Note: we're able to get `obj` and `propConfig` from `pointerToProp`,
|
||||||
|
@ -69,7 +69,7 @@ function createDerivation<T extends SerializablePrimitive>(
|
||||||
pointerToProp: Pointer<T>,
|
pointerToProp: Pointer<T>,
|
||||||
obj: SheetObject,
|
obj: SheetObject,
|
||||||
propConfig: PropTypeConfig_AllSimples,
|
propConfig: PropTypeConfig_AllSimples,
|
||||||
): IDerivation<EditingTools<T>> {
|
): Prism<EditingTools<T>> {
|
||||||
return prism(() => {
|
return prism(() => {
|
||||||
const pathToProp = getPointerParts(pointerToProp).path
|
const pathToProp = getPointerParts(pointerToProp).path
|
||||||
|
|
||||||
|
@ -329,7 +329,7 @@ function getDerivation<T extends SerializablePrimitive>(
|
||||||
pointerToProp: Pointer<T>,
|
pointerToProp: Pointer<T>,
|
||||||
obj: SheetObject,
|
obj: SheetObject,
|
||||||
propConfig: PropTypeConfig_AllSimples,
|
propConfig: PropTypeConfig_AllSimples,
|
||||||
): IDerivation<EditingTools<T>> {
|
): Prism<EditingTools<T>> {
|
||||||
if (cache.has(pointerToProp)) {
|
if (cache.has(pointerToProp)) {
|
||||||
return cache.get(pointerToProp)!
|
return cache.get(pointerToProp)!
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import type {IDerivation} from '@theatre/dataverse'
|
import type {Prism} from '@theatre/dataverse'
|
||||||
import {Box} from '@theatre/dataverse'
|
import {Box} from '@theatre/dataverse'
|
||||||
import useRefAndState from '@theatre/studio/utils/useRefAndState'
|
import useRefAndState from '@theatre/studio/utils/useRefAndState'
|
||||||
import React, {
|
import React, {
|
||||||
|
@ -10,7 +10,7 @@ import React, {
|
||||||
} from 'react'
|
} from 'react'
|
||||||
|
|
||||||
const ctx = createContext<{
|
const ctx = createContext<{
|
||||||
cur: IDerivation<number>
|
cur: Prism<number>
|
||||||
set: (id: number, delay: number) => void
|
set: (id: number, delay: number) => void
|
||||||
}>(null!)
|
}>(null!)
|
||||||
|
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
import {isDerivation, prism, val} from '@theatre/dataverse'
|
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 {useDerivation} from '@theatre/react'
|
||||||
import type {$IntentionalAny} from '@theatre/shared/utils/types'
|
import type {$IntentionalAny} from '@theatre/shared/utils/types'
|
||||||
import React, {useMemo, useRef} from 'react'
|
import React, {useMemo, useRef} from 'react'
|
||||||
import {invariant} from './invariant'
|
import {invariant} from './invariant'
|
||||||
|
|
||||||
type DeriveAll<T> = IDerivation<
|
type DeriveAll<T> = Prism<
|
||||||
{
|
{
|
||||||
[P in keyof T]: T[P] extends $<infer R> ? R : never
|
[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 [...$<any>[]]>(obj: T): DeriveAll<T>
|
||||||
function deriveAllD<T extends Record<string, $<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 {}> = (
|
type ReactDeriver<Props extends {}> = (
|
||||||
props: {
|
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">
|
? TSErrors<"Can't both use Derivation properties while wrapping with deriver">
|
||||||
: Props[P] | IDerivation<Props[P]>
|
: Props[P] | Prism<Props[P]>
|
||||||
},
|
},
|
||||||
) => React.ReactElement | null
|
) => React.ReactElement | null
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ export function deriver<Props extends {}>(
|
||||||
ref,
|
ref,
|
||||||
) {
|
) {
|
||||||
let observableArr = []
|
let observableArr = []
|
||||||
const observables: Record<string, IDerivation<$IntentionalAny>> = {}
|
const observables: Record<string, Prism<$IntentionalAny>> = {}
|
||||||
const normalProps: Record<string, $IntentionalAny> = {
|
const normalProps: Record<string, $IntentionalAny> = {
|
||||||
ref,
|
ref,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue