Unify Derivation and Prism 2/n

This commit is contained in:
Aria Minaei 2022-12-01 14:22:49 +01:00
parent 12b3f477bc
commit bfba1d4879
8 changed files with 17 additions and 17 deletions

View file

@ -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

View file

@ -10,7 +10,7 @@ export interface Prism<V> {
/**
* Whether the object is a derivation.
*/
isDerivation: true
isPrism: true
/**
* Whether the derivation is hot.
@ -63,6 +63,6 @@ export interface Prism<V> {
/**
* Returns whether `d` is a derivation.
*/
export function isDerivation(d: any): d is Prism<unknown> {
return d && d.isDerivation && d.isDerivation === true
export function isPrism(d: any): d is Prism<unknown> {
return d && d.isPrism && d.isPrism === true
}

View file

@ -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<V>(
pointerOrDerivation: Prism<V> | Pointer<V>,
@ -10,7 +10,7 @@ export default function* iterateAndCountTicks<V>(
let d
if (isPointer(pointerOrDerivation)) {
d = valueDerivation(pointerOrDerivation) as Prism<V>
} else if (isDerivation(pointerOrDerivation)) {
} else if (isPrism(pointerOrDerivation)) {
d = pointerOrDerivation
} else {
throw new Error(`Only pointers and derivations are supported`)

View file

@ -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<V>(
pointerOrDerivation: Prism<V> | Pointer<V>,
@ -11,7 +11,7 @@ export default function* iterateOver<V>(
let d
if (isPointer(pointerOrDerivation)) {
d = valueDerivation(pointerOrDerivation) as Prism<V>
} else if (isDerivation(pointerOrDerivation)) {
} else if (isPrism(pointerOrDerivation)) {
d = pointerOrDerivation
} else {
throw new Error(`Only pointers and derivations are supported`)

View file

@ -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<V> implements Prism<V> {
/**
* 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 = <P extends Prism<$IntentionalAny> | unknown>(
input: P,
): P extends Prism<infer T> ? T : P => {
if (isDerivation(input)) {
if (isPrism(input)) {
return input.getValue() as $IntentionalAny
} else {
return input as $IntentionalAny

View file

@ -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'