Fix: Dataverse.isPointer() returns a bool now

This commit is contained in:
Aria Minaei 2021-06-27 13:37:10 +02:00
parent 0dfe630a4f
commit 1e52c7de7e
5 changed files with 14 additions and 9 deletions

View file

@ -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<State extends {}>
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 = <P extends PointerType<$IntentionalAny>>(
return derivation as $IntentionalAny
}
export function isIdentityChangeProvider(
function isIdentityChangeProvider(
val: unknown,
): val is IdentityDerivationProvider {
return (
@ -235,7 +238,3 @@ export const val = <P>(
return pointerOrDerivationOrPlainValue as $IntentionalAny
}
}
export const isPointer = (p: $IntentionalAny): p is Pointer<unknown> => {
return p && p.$pointerMeta ? true : false
}

View file

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

View file

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

View file

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

View file

@ -102,3 +102,7 @@ function pointer(args: {root: {}; path?: Array<string | number>}) {
}
export default pointer
export const isPointer = (p: $IntentionalAny): p is Pointer<unknown> => {
return p && !!getPointerMeta(p)
}