Unify Derivation and Prism 8/n

This commit is contained in:
Aria Minaei 2022-12-01 14:44:38 +01:00
parent acf34d393d
commit 27b9c96afd
3 changed files with 9 additions and 9 deletions

View file

@ -41,7 +41,7 @@ function useForceUpdate(debugLabel?: string) {
/**
* A React hook that executes the callback function and returns its return value
* whenever there's a change in the values of the dependency array, or in the
* derivations that are used within the callback function.
* prisms that are used within the callback function.
*
* @param fn - The callback function
* @param deps - The dependency array
@ -285,7 +285,7 @@ function queueIfNeeded() {
*
* ```ts
* const num = new Box(1)
* const isPositiveD = prism(() => num.derivation.getValue() >= 0)
* const isPositiveD = prism(() => num.prism.getValue() >= 0)
*
* const Comp = () => {
* return <div>{useDerivation(isPositiveD)}</div>

View file

@ -38,7 +38,7 @@ export default class Sequence {
publicApi: TheatreSequence
private _playbackControllerBox: IBox<IPlaybackController>
private _statePointerDerivation: Prism<Pointer<IPlaybackState>>
private _prismOfStatePointer: Prism<Pointer<IPlaybackState>>
private _positionD: Prism<number>
private _positionFormatterD: Prism<ISequencePositionFormatter>
_playableRangeD: undefined | Prism<{start: number; end: number}>
@ -66,12 +66,12 @@ export default class Sequence {
playbackController ?? new DefaultPlaybackController(getCoreTicker()),
)
this._statePointerDerivation = prism(
this._prismOfStatePointer = prism(
() => this._playbackControllerBox.prism.getValue().statePointer,
)
this._positionD = prism(() => {
const statePointer = this._statePointerDerivation.getValue()
const statePointer = this._prismOfStatePointer.getValue()
return val(statePointer.position)
})
@ -99,7 +99,7 @@ export default class Sequence {
return this._positionD
} else if (prop === 'playing') {
return prism(() => {
return val(this._statePointerDerivation.getValue().playing)
return val(this._prismOfStatePointer.getValue().playing)
})
} else {
return prism(() => undefined)
@ -110,8 +110,8 @@ export default class Sequence {
return this._positionFormatterD.getValue()
}
get derivationToStatePointer() {
return this._statePointerDerivation
get prismOfStatePointer() {
return this._prismOfStatePointer
}
get length() {

View file

@ -85,7 +85,7 @@ export default class SheetObject implements IdentityPrismProvider {
* if boo.bar.baz is sequenced and the sequence is playing, this prism will recalculate on every frame.
* This might sound inefficient, but we have a few tricks to make it fast:
*
* First, on each recalculation, most of the derivations that this prism depends on will not have changed,
* First, on each recalculation, most of the prisms that this prism depends on will not have changed,
* and so reading them is cheap. For example, if foo.bar.baz changed due to being sequenced, but
* foo.bar2 hasn't because it is static, reading foo.bar2 will be cheap.
*