Unify Derivation and Prism 2/n
This commit is contained in:
parent
12b3f477bc
commit
bfba1d4879
8 changed files with 17 additions and 17 deletions
|
@ -2,7 +2,7 @@ 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 {Prism} from './derivations/IDerivation'
|
import type {Prism} from './derivations/IDerivation'
|
||||||
import {isDerivation} from './derivations/IDerivation'
|
import {isPrism} from './derivations/IDerivation'
|
||||||
import type {Pointer, PointerType} from './pointer'
|
import type {Pointer, PointerType} from './pointer'
|
||||||
import {isPointer} from './pointer'
|
import {isPointer} from './pointer'
|
||||||
import pointer, {getPointerMeta} from './pointer'
|
import pointer, {getPointerMeta} from './pointer'
|
||||||
|
@ -323,7 +323,7 @@ export const val = <
|
||||||
: unknown => {
|
: unknown => {
|
||||||
if (isPointer(input)) {
|
if (isPointer(input)) {
|
||||||
return valueDerivation(input).getValue() as $IntentionalAny
|
return valueDerivation(input).getValue() as $IntentionalAny
|
||||||
} else if (isDerivation(input)) {
|
} else if (isPrism(input)) {
|
||||||
return input.getValue() as $IntentionalAny
|
return input.getValue() as $IntentionalAny
|
||||||
} else {
|
} else {
|
||||||
return input as $IntentionalAny
|
return input as $IntentionalAny
|
||||||
|
|
|
@ -10,7 +10,7 @@ export interface Prism<V> {
|
||||||
/**
|
/**
|
||||||
* Whether the object is a derivation.
|
* Whether the object is a derivation.
|
||||||
*/
|
*/
|
||||||
isDerivation: true
|
isPrism: true
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether the derivation is hot.
|
* Whether the derivation is hot.
|
||||||
|
@ -63,6 +63,6 @@ export interface Prism<V> {
|
||||||
/**
|
/**
|
||||||
* Returns whether `d` is a derivation.
|
* Returns whether `d` is a derivation.
|
||||||
*/
|
*/
|
||||||
export function isDerivation(d: any): d is Prism<unknown> {
|
export function isPrism(d: any): d is Prism<unknown> {
|
||||||
return d && d.isDerivation && d.isDerivation === true
|
return d && d.isPrism && d.isPrism === true
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ import {valueDerivation} from '../Atom'
|
||||||
import type {Pointer} from '../pointer'
|
import type {Pointer} from '../pointer'
|
||||||
import {isPointer} from '../pointer'
|
import {isPointer} from '../pointer'
|
||||||
import type {Prism} from './IDerivation'
|
import type {Prism} from './IDerivation'
|
||||||
import {isDerivation} from './IDerivation'
|
import {isPrism} from './IDerivation'
|
||||||
|
|
||||||
export default function* iterateAndCountTicks<V>(
|
export default function* iterateAndCountTicks<V>(
|
||||||
pointerOrDerivation: Prism<V> | Pointer<V>,
|
pointerOrDerivation: Prism<V> | Pointer<V>,
|
||||||
|
@ -10,7 +10,7 @@ export default function* iterateAndCountTicks<V>(
|
||||||
let d
|
let d
|
||||||
if (isPointer(pointerOrDerivation)) {
|
if (isPointer(pointerOrDerivation)) {
|
||||||
d = valueDerivation(pointerOrDerivation) as Prism<V>
|
d = valueDerivation(pointerOrDerivation) as Prism<V>
|
||||||
} else if (isDerivation(pointerOrDerivation)) {
|
} else if (isPrism(pointerOrDerivation)) {
|
||||||
d = pointerOrDerivation
|
d = pointerOrDerivation
|
||||||
} else {
|
} else {
|
||||||
throw new Error(`Only pointers and derivations are supported`)
|
throw new Error(`Only pointers and derivations are supported`)
|
||||||
|
|
|
@ -3,7 +3,7 @@ import type {Pointer} from '../pointer'
|
||||||
import {isPointer} from '../pointer'
|
import {isPointer} from '../pointer'
|
||||||
import Ticker from '../Ticker'
|
import Ticker from '../Ticker'
|
||||||
import type {Prism} from './IDerivation'
|
import type {Prism} from './IDerivation'
|
||||||
import {isDerivation} from './IDerivation'
|
import {isPrism} from './IDerivation'
|
||||||
|
|
||||||
export default function* iterateOver<V>(
|
export default function* iterateOver<V>(
|
||||||
pointerOrDerivation: Prism<V> | Pointer<V>,
|
pointerOrDerivation: Prism<V> | Pointer<V>,
|
||||||
|
@ -11,7 +11,7 @@ export default function* iterateOver<V>(
|
||||||
let d
|
let d
|
||||||
if (isPointer(pointerOrDerivation)) {
|
if (isPointer(pointerOrDerivation)) {
|
||||||
d = valueDerivation(pointerOrDerivation) as Prism<V>
|
d = valueDerivation(pointerOrDerivation) as Prism<V>
|
||||||
} else if (isDerivation(pointerOrDerivation)) {
|
} else if (isPrism(pointerOrDerivation)) {
|
||||||
d = pointerOrDerivation
|
d = pointerOrDerivation
|
||||||
} else {
|
} else {
|
||||||
throw new Error(`Only pointers and derivations are supported`)
|
throw new Error(`Only pointers and derivations are supported`)
|
||||||
|
|
|
@ -2,7 +2,7 @@ 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 {Prism} from '../IDerivation'
|
import type {Prism} from '../IDerivation'
|
||||||
import {isDerivation} from '../IDerivation'
|
import {isPrism} from '../IDerivation'
|
||||||
import {
|
import {
|
||||||
startIgnoringDependencies,
|
startIgnoringDependencies,
|
||||||
stopIgnoringDependencies,
|
stopIgnoringDependencies,
|
||||||
|
@ -202,7 +202,7 @@ class PrismDerivation<V> implements Prism<V> {
|
||||||
/**
|
/**
|
||||||
* Whether the object is a derivation.
|
* Whether the object is a derivation.
|
||||||
*/
|
*/
|
||||||
readonly isDerivation: true = true
|
readonly isPrism: true = true
|
||||||
|
|
||||||
private _state:
|
private _state:
|
||||||
| {hot: false; handle: undefined}
|
| {hot: false; handle: undefined}
|
||||||
|
@ -703,7 +703,7 @@ function inPrism(): boolean {
|
||||||
const possibleDerivationToValue = <P extends Prism<$IntentionalAny> | unknown>(
|
const possibleDerivationToValue = <P extends Prism<$IntentionalAny> | unknown>(
|
||||||
input: P,
|
input: P,
|
||||||
): P extends Prism<infer T> ? T : P => {
|
): P extends Prism<infer T> ? T : P => {
|
||||||
if (isDerivation(input)) {
|
if (isPrism(input)) {
|
||||||
return input.getValue() as $IntentionalAny
|
return input.getValue() as $IntentionalAny
|
||||||
} else {
|
} else {
|
||||||
return input as $IntentionalAny
|
return input as $IntentionalAny
|
||||||
|
|
|
@ -8,7 +8,7 @@ export type {IdentityDerivationProvider} from './Atom'
|
||||||
export {default as Atom, val, valueDerivation} from './Atom'
|
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 {isPrism} from './derivations/IDerivation'
|
||||||
export type {Prism} 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'
|
||||||
|
|
|
@ -10,7 +10,7 @@ import userReadableTypeOfValue from '@theatre/shared/utils/userReadableTypeOfVal
|
||||||
import deepEqual from 'fast-deep-equal'
|
import deepEqual from 'fast-deep-equal'
|
||||||
import type {PointerType} from '@theatre/dataverse'
|
import type {PointerType} from '@theatre/dataverse'
|
||||||
import {isPointer} 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 {$IntentionalAny, VoidFn} from '@theatre/shared/utils/types'
|
||||||
import type {ProjectId} from '@theatre/shared/utils/ids'
|
import type {ProjectId} from '@theatre/shared/utils/ids'
|
||||||
import {_coreLogger} from './_coreLogger'
|
import {_coreLogger} from './_coreLogger'
|
||||||
|
@ -161,7 +161,7 @@ export function onChange<P extends PointerType<$IntentionalAny>>(
|
||||||
callback as $IntentionalAny,
|
callback as $IntentionalAny,
|
||||||
true,
|
true,
|
||||||
)
|
)
|
||||||
} else if (isDerivation(pointer)) {
|
} else if (isPrism(pointer)) {
|
||||||
return pointer.onChange(getCoreTicker(), callback as $IntentionalAny, true)
|
return pointer.onChange(getCoreTicker(), callback as $IntentionalAny, true)
|
||||||
} else {
|
} else {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
|
|
|
@ -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 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'
|
||||||
|
@ -70,7 +70,7 @@ export function deriver<Props extends {}>(
|
||||||
}
|
}
|
||||||
for (const key in props) {
|
for (const key in props) {
|
||||||
const value = props[key]
|
const value = props[key]
|
||||||
if (isDerivation(value)) {
|
if (isPrism(value)) {
|
||||||
observableArr.push(value)
|
observableArr.push(value)
|
||||||
observables[key] = value
|
observables[key] = value
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue