diff --git a/packages/dataverse/src/Atom.ts b/packages/dataverse/src/Atom.ts index 1169e59..af7945a 100644 --- a/packages/dataverse/src/Atom.ts +++ b/packages/dataverse/src/Atom.ts @@ -5,6 +5,7 @@ import DerivationFromSource from './derivations/DerivationFromSource' import type {IDerivation} from './derivations/IDerivation' import {isDerivation} from './derivations/IDerivation' import type {Pointer, PointerType} from './pointer' +import {isPointer} from './pointer' import pointer, {getPointerMeta} from './pointer' import type {$FixMe, $IntentionalAny} from './types' import type {PathBasedReducer} from './utils/PathBasedReducer' @@ -145,6 +146,8 @@ export default class Atom scope.identityChangeListeners.forEach((cb) => cb(newState)) if (scope.children.size === 0) return + + // @todo we can probably skip checking value types const oldValueType = getTypeOfValue(oldState) const newValueType = getTypeOfValue(newState) @@ -208,7 +211,7 @@ export const valueDerivation =

>( return derivation as $IntentionalAny } -export function isIdentityChangeProvider( +function isIdentityChangeProvider( val: unknown, ): val is IdentityDerivationProvider { return ( @@ -235,7 +238,3 @@ export const val =

( return pointerOrDerivationOrPlainValue as $IntentionalAny } } - -export const isPointer = (p: $IntentionalAny): p is Pointer => { - return p && p.$pointerMeta ? true : false -} diff --git a/packages/dataverse/src/derivations/iterateAndCountTicks.ts b/packages/dataverse/src/derivations/iterateAndCountTicks.ts index 3f8b76b..37030fb 100644 --- a/packages/dataverse/src/derivations/iterateAndCountTicks.ts +++ b/packages/dataverse/src/derivations/iterateAndCountTicks.ts @@ -1,5 +1,6 @@ -import {isPointer, valueDerivation} from '../Atom' +import {valueDerivation} from '../Atom' import type {Pointer} from '../pointer' +import {isPointer} from '../pointer' import type {IDerivation} from './IDerivation' import {isDerivation} from './IDerivation' diff --git a/packages/dataverse/src/derivations/iterateOver.ts b/packages/dataverse/src/derivations/iterateOver.ts index a46a96e..f800002 100644 --- a/packages/dataverse/src/derivations/iterateOver.ts +++ b/packages/dataverse/src/derivations/iterateOver.ts @@ -1,5 +1,6 @@ -import {isPointer, valueDerivation} from '../Atom' +import {valueDerivation} from '../Atom' import type {Pointer} from '../pointer' +import {isPointer} from '../pointer' import Ticker from '../Ticker' import type {IDerivation} from './IDerivation' import {isDerivation} from './IDerivation' diff --git a/packages/dataverse/src/index.ts b/packages/dataverse/src/index.ts index 09ce3ce..dbf2477 100644 --- a/packages/dataverse/src/index.ts +++ b/packages/dataverse/src/index.ts @@ -1,4 +1,4 @@ -export {default as Atom, isPointer, val, valueDerivation} from './Atom' +export {default as Atom, val, valueDerivation} from './Atom' export {default as Box} from './Box' export type {IBox} from './Box' export {default as AbstractDerivation} from './derivations/AbstractDerivation' @@ -9,7 +9,7 @@ export type {IDerivation} from './derivations/IDerivation' export {default as iterateAndCountTicks} from './derivations/iterateAndCountTicks' export {default as iterateOver} from './derivations/iterateOver' export {default as prism} from './derivations/prism/prism' -export {default as pointer, getPointerParts} from './pointer' +export {default as pointer, getPointerParts, isPointer} from './pointer' export type {Pointer} from './pointer' export {default as Ticker} from './Ticker' export {default as PointerProxy} from './PointerProxy' diff --git a/packages/dataverse/src/pointer.ts b/packages/dataverse/src/pointer.ts index 6f9373b..ba5c813 100644 --- a/packages/dataverse/src/pointer.ts +++ b/packages/dataverse/src/pointer.ts @@ -102,3 +102,7 @@ function pointer(args: {root: {}; path?: Array}) { } export default pointer + +export const isPointer = (p: $IntentionalAny): p is Pointer => { + return p && !!getPointerMeta(p) +}