From bfba1d48795a04c1d2d98c1e525c74d6afd8f00a Mon Sep 17 00:00:00 2001 From: Aria Minaei Date: Thu, 1 Dec 2022 14:22:49 +0100 Subject: [PATCH] Unify Derivation and Prism 2/n --- packages/dataverse/src/Atom.ts | 4 ++-- packages/dataverse/src/derivations/IDerivation.ts | 6 +++--- packages/dataverse/src/derivations/iterateAndCountTicks.ts | 4 ++-- packages/dataverse/src/derivations/iterateOver.ts | 4 ++-- packages/dataverse/src/derivations/prism/prism.ts | 6 +++--- packages/dataverse/src/index.ts | 2 +- theatre/core/src/coreExports.ts | 4 ++-- theatre/studio/src/utils/derive-utils.tsx | 4 ++-- 8 files changed, 17 insertions(+), 17 deletions(-) diff --git a/packages/dataverse/src/Atom.ts b/packages/dataverse/src/Atom.ts index 172c39a..f6ee460 100644 --- a/packages/dataverse/src/Atom.ts +++ b/packages/dataverse/src/Atom.ts @@ -2,7 +2,7 @@ import get from 'lodash-es/get' import isPlainObject from 'lodash-es/isPlainObject' import last from 'lodash-es/last' import type {Prism} from './derivations/IDerivation' -import {isDerivation} from './derivations/IDerivation' +import {isPrism} from './derivations/IDerivation' import type {Pointer, PointerType} from './pointer' import {isPointer} from './pointer' import pointer, {getPointerMeta} from './pointer' @@ -323,7 +323,7 @@ export const val = < : unknown => { if (isPointer(input)) { return valueDerivation(input).getValue() as $IntentionalAny - } else if (isDerivation(input)) { + } else if (isPrism(input)) { return input.getValue() as $IntentionalAny } else { return input as $IntentionalAny diff --git a/packages/dataverse/src/derivations/IDerivation.ts b/packages/dataverse/src/derivations/IDerivation.ts index 202110d..d215566 100644 --- a/packages/dataverse/src/derivations/IDerivation.ts +++ b/packages/dataverse/src/derivations/IDerivation.ts @@ -10,7 +10,7 @@ export interface Prism { /** * Whether the object is a derivation. */ - isDerivation: true + isPrism: true /** * Whether the derivation is hot. @@ -63,6 +63,6 @@ export interface Prism { /** * Returns whether `d` is a derivation. */ -export function isDerivation(d: any): d is Prism { - return d && d.isDerivation && d.isDerivation === true +export function isPrism(d: any): d is Prism { + return d && d.isPrism && d.isPrism === true } diff --git a/packages/dataverse/src/derivations/iterateAndCountTicks.ts b/packages/dataverse/src/derivations/iterateAndCountTicks.ts index 586e558..c19aeb5 100644 --- a/packages/dataverse/src/derivations/iterateAndCountTicks.ts +++ b/packages/dataverse/src/derivations/iterateAndCountTicks.ts @@ -2,7 +2,7 @@ import {valueDerivation} from '../Atom' import type {Pointer} from '../pointer' import {isPointer} from '../pointer' import type {Prism} from './IDerivation' -import {isDerivation} from './IDerivation' +import {isPrism} from './IDerivation' export default function* iterateAndCountTicks( pointerOrDerivation: Prism | Pointer, @@ -10,7 +10,7 @@ export default function* iterateAndCountTicks( let d if (isPointer(pointerOrDerivation)) { d = valueDerivation(pointerOrDerivation) as Prism - } else if (isDerivation(pointerOrDerivation)) { + } else if (isPrism(pointerOrDerivation)) { d = pointerOrDerivation } else { throw new Error(`Only pointers and derivations are supported`) diff --git a/packages/dataverse/src/derivations/iterateOver.ts b/packages/dataverse/src/derivations/iterateOver.ts index 1071d04..b629a81 100644 --- a/packages/dataverse/src/derivations/iterateOver.ts +++ b/packages/dataverse/src/derivations/iterateOver.ts @@ -3,7 +3,7 @@ import type {Pointer} from '../pointer' import {isPointer} from '../pointer' import Ticker from '../Ticker' import type {Prism} from './IDerivation' -import {isDerivation} from './IDerivation' +import {isPrism} from './IDerivation' export default function* iterateOver( pointerOrDerivation: Prism | Pointer, @@ -11,7 +11,7 @@ export default function* iterateOver( let d if (isPointer(pointerOrDerivation)) { d = valueDerivation(pointerOrDerivation) as Prism - } else if (isDerivation(pointerOrDerivation)) { + } else if (isPrism(pointerOrDerivation)) { d = pointerOrDerivation } else { throw new Error(`Only pointers and derivations are supported`) diff --git a/packages/dataverse/src/derivations/prism/prism.ts b/packages/dataverse/src/derivations/prism/prism.ts index 8f3337a..59e5d86 100644 --- a/packages/dataverse/src/derivations/prism/prism.ts +++ b/packages/dataverse/src/derivations/prism/prism.ts @@ -2,7 +2,7 @@ import type Ticker from '../../Ticker' import type {$IntentionalAny, VoidFn} from '../../types' import Stack from '../../utils/Stack' import type {Prism} from '../IDerivation' -import {isDerivation} from '../IDerivation' +import {isPrism} from '../IDerivation' import { startIgnoringDependencies, stopIgnoringDependencies, @@ -202,7 +202,7 @@ class PrismDerivation implements Prism { /** * Whether the object is a derivation. */ - readonly isDerivation: true = true + readonly isPrism: true = true private _state: | {hot: false; handle: undefined} @@ -703,7 +703,7 @@ function inPrism(): boolean { const possibleDerivationToValue =

| unknown>( input: P, ): P extends Prism ? T : P => { - if (isDerivation(input)) { + if (isPrism(input)) { return input.getValue() as $IntentionalAny } else { return input as $IntentionalAny diff --git a/packages/dataverse/src/index.ts b/packages/dataverse/src/index.ts index 7f3d15c..86eb546 100644 --- a/packages/dataverse/src/index.ts +++ b/packages/dataverse/src/index.ts @@ -8,7 +8,7 @@ export type {IdentityDerivationProvider} from './Atom' 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 {isPrism} from './derivations/IDerivation' export type {Prism} from './derivations/IDerivation' export {default as iterateAndCountTicks} from './derivations/iterateAndCountTicks' export {default as iterateOver} from './derivations/iterateOver' diff --git a/theatre/core/src/coreExports.ts b/theatre/core/src/coreExports.ts index 8210e36..722c8f4 100644 --- a/theatre/core/src/coreExports.ts +++ b/theatre/core/src/coreExports.ts @@ -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 {isDerivation, valueDerivation} from '@theatre/dataverse' +import {isPrism, valueDerivation} from '@theatre/dataverse' import type {$IntentionalAny, VoidFn} from '@theatre/shared/utils/types' import type {ProjectId} from '@theatre/shared/utils/ids' import {_coreLogger} from './_coreLogger' @@ -161,7 +161,7 @@ export function onChange

>( callback as $IntentionalAny, true, ) - } else if (isDerivation(pointer)) { + } else if (isPrism(pointer)) { return pointer.onChange(getCoreTicker(), callback as $IntentionalAny, true) } else { throw new Error( diff --git a/theatre/studio/src/utils/derive-utils.tsx b/theatre/studio/src/utils/derive-utils.tsx index a3f3c31..9c363ab 100644 --- a/theatre/studio/src/utils/derive-utils.tsx +++ b/theatre/studio/src/utils/derive-utils.tsx @@ -1,4 +1,4 @@ -import {isDerivation, prism, val} from '@theatre/dataverse' +import {isPrism, prism, val} from '@theatre/dataverse' import type {Prism, Pointer} from '@theatre/dataverse' import {useDerivation} from '@theatre/react' import type {$IntentionalAny} from '@theatre/shared/utils/types' @@ -70,7 +70,7 @@ export function deriver( } for (const key in props) { const value = props[key] - if (isDerivation(value)) { + if (isPrism(value)) { observableArr.push(value) observables[key] = value } else {