Unify Derivation and Prism 4/n

This commit is contained in:
Aria Minaei 2022-12-01 14:26:17 +01:00
parent 06808f99e9
commit a38d96ec95
10 changed files with 26 additions and 26 deletions

View file

@ -266,7 +266,7 @@ const identityDerivationWeakMap = new WeakMap<{}, Prism<unknown>>()
*
* @param pointer - The pointer to return the derivation at.
*/
export const valueDerivation = <P extends PointerType<$IntentionalAny>>(
export const pointerToPrism = <P extends PointerType<$IntentionalAny>>(
pointer: P,
): Prism<P extends PointerType<infer T> ? T : void> => {
const meta = getPointerMeta(pointer)
@ -276,7 +276,7 @@ export const valueDerivation = <P extends PointerType<$IntentionalAny>>(
const root = meta.root
if (!isIdentityDerivationProvider(root)) {
throw new Error(
`Cannot run valueDerivation() on a pointer whose root is not an IdentityChangeProvider`,
`Cannot run pointerToPrism() on a pointer whose root is not an IdentityChangeProvider`,
)
}
const {path} = meta
@ -322,7 +322,7 @@ export const val = <
? P
: unknown => {
if (isPointer(input)) {
return valueDerivation(input).getValue() as $IntentionalAny
return pointerToPrism(input).getValue() as $IntentionalAny
} else if (isPrism(input)) {
return input.getValue() as $IntentionalAny
} else {

View file

@ -26,7 +26,7 @@ export default class PointerProxy<O extends {}>
* Convenience pointer pointing to the root of this PointerProxy.
*
* @remarks
* Allows convenient use of {@link valueDerivation} and {@link val}.
* Allows convenient use of {@link pointerToPrism} and {@link val}.
*/
readonly pointer: Pointer<O>

View file

@ -1,4 +1,4 @@
import {valueDerivation} from '../Atom'
import {pointerToPrism} from '../Atom'
import type {Pointer} from '../pointer'
import {isPointer} from '../pointer'
import type {Prism} from './Interface'
@ -9,7 +9,7 @@ export default function* iterateAndCountTicks<V>(
): Generator<{value: V; ticks: number}, void, void> {
let d
if (isPointer(pointerOrDerivation)) {
d = valueDerivation(pointerOrDerivation) as Prism<V>
d = pointerToPrism(pointerOrDerivation) as Prism<V>
} else if (isPrism(pointerOrDerivation)) {
d = pointerOrDerivation
} else {

View file

@ -1,4 +1,4 @@
import {valueDerivation} from '../Atom'
import {pointerToPrism} from '../Atom'
import type {Pointer} from '../pointer'
import {isPointer} from '../pointer'
import Ticker from '../Ticker'
@ -10,7 +10,7 @@ export default function* iterateOver<V>(
): Generator<V, void, void> {
let d
if (isPointer(pointerOrDerivation)) {
d = valueDerivation(pointerOrDerivation) as Prism<V>
d = pointerToPrism(pointerOrDerivation) as Prism<V>
} else if (isPrism(pointerOrDerivation)) {
d = pointerOrDerivation
} else {

View file

@ -5,7 +5,7 @@
*/
export type {IdentityDerivationProvider} from './Atom'
export {default as Atom, val, valueDerivation} from './Atom'
export {default as Atom, val, pointerToPrism} from './Atom'
export {default as Box} from './Box'
export type {IBox} from './Box'
export {isPrism} from './derivations/Interface'

View file

@ -10,7 +10,7 @@ import userReadableTypeOfValue from '@theatre/shared/utils/userReadableTypeOfVal
import deepEqual from 'fast-deep-equal'
import type {PointerType} from '@theatre/dataverse'
import {isPointer} from '@theatre/dataverse'
import {isPrism, valueDerivation} from '@theatre/dataverse'
import {isPrism, pointerToPrism} from '@theatre/dataverse'
import type {$IntentionalAny, VoidFn} from '@theatre/shared/utils/types'
import type {ProjectId} from '@theatre/shared/utils/ids'
import {_coreLogger} from './_coreLogger'
@ -155,7 +155,7 @@ export function onChange<P extends PointerType<$IntentionalAny>>(
callback: (value: P extends PointerType<infer T> ? T : unknown) => void,
): VoidFn {
if (isPointer(pointer)) {
const derivation = valueDerivation(pointer)
const derivation = pointerToPrism(pointer)
return derivation.onChange(
getCoreTicker(),
callback as $IntentionalAny,
@ -189,7 +189,7 @@ export function onChange<P extends PointerType<$IntentionalAny>>(
*/
export function val<T>(pointer: PointerType<T>): T {
if (isPointer(pointer)) {
return valueDerivation(pointer).getValue() as $IntentionalAny
return pointerToPrism(pointer).getValue() as $IntentionalAny
} else {
throw new Error(`Called val(p) where p is not a pointer.`)
}

View file

@ -2,7 +2,7 @@ import Scrub from '@theatre/studio/Scrub'
import type {StudioHistoricState} from '@theatre/studio/store/types/historic'
import type UI from '@theatre/studio/UI'
import type {Pointer} from '@theatre/dataverse'
import {Atom, PointerProxy, valueDerivation} from '@theatre/dataverse'
import {Atom, PointerProxy, pointerToPrism} from '@theatre/dataverse'
import type {
CommitOrDiscard,
ITransactionPrivateApi,
@ -171,7 +171,7 @@ export class Studio {
}
_attachToIncomingProjects() {
const projectsD = valueDerivation(this.projectsP)
const projectsD = pointerToPrism(this.projectsP)
const attachToProjects = (projects: Record<string, Project>) => {
for (const project of Object.values(projects)) {

View file

@ -9,7 +9,7 @@ import type {
} from '@theatre/studio/panels/SequenceEditorPanel/layout/tree'
import {usePrism, useVal} from '@theatre/react'
import type {Prism, Pointer} from '@theatre/dataverse'
import {prism, val, valueDerivation} from '@theatre/dataverse'
import {prism, val, pointerToPrism} from '@theatre/dataverse'
import React, {useMemo, Fragment} from 'react'
import styled from 'styled-components'
import type {IContextMenuItem} from '@theatre/studio/uiComponents/simpleContextMenu/useContextMenu'
@ -302,7 +302,7 @@ function useAggregatedKeyframeTrackContextMenu(
displayName: 'Aggregate Keyframe Track',
menuItems: () => {
const selectionKeyframes =
valueDerivation(
pointerToPrism(
getStudio()!.atomP.ahistoric.clipboard.keyframesWithRelativePaths,
).getValue() ?? []
@ -355,7 +355,7 @@ function pasteKeyframesSheet(
if (areKeyframesAllOnSingleTrack) {
for (const object of viewModel.children.map((child) => child.sheetObject)) {
const tracksByObject = valueDerivation(
const tracksByObject = pointerToPrism(
getStudio().atomP.historic.coreByProject[projectId].sheetsById[sheetId]
.sequence.tracksByObject[object.address.objectKey],
).getValue()
@ -370,7 +370,7 @@ function pasteKeyframesSheet(
)
}
} else {
const tracksByObject = valueDerivation(
const tracksByObject = pointerToPrism(
getStudio().atomP.historic.coreByProject[projectId].sheetsById[sheetId]
.sequence.tracksByObject,
).getValue()
@ -418,7 +418,7 @@ function pasteKeyframesObjectOrCompound(
) {
const {projectId, sheetId, objectKey} = viewModel.sheetObject.address
const trackRecords = valueDerivation(
const trackRecords = pointerToPrism(
getStudio().atomP.historic.coreByProject[projectId].sheetsById[sheetId]
.sequence.tracksByObject[objectKey],
).getValue()

View file

@ -13,7 +13,7 @@ import type {
} from '@theatre/shared/utils/ids'
import {createStudioSheetItemKey} from '@theatre/shared/utils/ids'
import type {$FixMe, $IntentionalAny} from '@theatre/shared/utils/types'
import {prism, val, valueDerivation} from '@theatre/dataverse'
import {prism, val, pointerToPrism} from '@theatre/dataverse'
import logger from '@theatre/shared/logger'
import {titleBarHeight} from '@theatre/studio/panels/BasePanel/common'
import type {Studio} from '@theatre/studio/Studio'
@ -116,7 +116,7 @@ export const calculateSequenceEditorTree = (
const isCollapsedP =
collapsableItemSetP.byId[createStudioSheetItemKey.forSheet()].isCollapsed
const isCollapsed = valueDerivation(isCollapsedP).getValue() ?? false
const isCollapsed = pointerToPrism(isCollapsedP).getValue() ?? false
const tree: SequenceEditorTree = {
type: 'sheet',
@ -165,7 +165,7 @@ export const calculateSequenceEditorTree = (
collapsableItemSetP.byId[
createStudioSheetItemKey.forSheetObject(sheetObject)
].isCollapsed
const isCollapsed = valueDerivation(isCollapsedP).getValue() ?? false
const isCollapsed = pointerToPrism(isCollapsedP).getValue() ?? false
const row: SequenceEditorTree_SheetObject = {
type: 'sheetObject',
@ -284,7 +284,7 @@ export const calculateSequenceEditorTree = (
collapsableItemSetP.byId[
createStudioSheetItemKey.forSheetObjectProp(sheetObject, pathToProp)
].isCollapsed
const isCollapsed = valueDerivation(isCollapsedP).getValue() ?? false
const isCollapsed = pointerToPrism(isCollapsedP).getValue() ?? false
const row: SequenceEditorTree_PropWithChildren = {
type: 'propWithChildren',

View file

@ -3,7 +3,7 @@ import type {StrictRecord} from '@theatre/shared/utils/types'
import React, {useMemo} from 'react'
import {useEffect} from 'react'
import {useLogger} from './useLogger'
import {Box, prism, valueDerivation} from '@theatre/dataverse'
import {Box, prism, pointerToPrism} from '@theatre/dataverse'
import {Atom} from '@theatre/dataverse'
import {useDerivation} from '@theatre/react'
import {selectClosestHTMLAncestor} from '@theatre/studio/utils/selectClosestHTMLAncestor'
@ -69,10 +69,10 @@ function createPresenceContext(options: {
if (!itemKey) return undefinedD
// this is the thing being hovered
const currentD = currentUserHoverItemB.derivation
const primaryFocusDer = valueDerivation(
const primaryFocusDer = pointerToPrism(
currentUserHoverFlagItemsAtom.pointer[itemKey],
)
const relationsDer = valueDerivation(relationsAtom.pointer[itemKey])
const relationsDer = pointerToPrism(relationsAtom.pointer[itemKey])
return prism(() => {
const primary = primaryFocusDer.getValue()
if (primary) {