chore: exports fns

main
CCherry07 8 months ago
parent 61aefead9c
commit 291a0cfed2
  1. 4
      src/core.ts
  2. 13
      src/index.ts
  3. 2
      src/utils.ts
  4. 14
      src/watch.ts

@ -1,5 +1,6 @@
import { createReactiveSystem, Dependency, Link, Subscriber, SubscriberFlags } from 'alien-signals'; import { createReactiveSystem, Dependency, Link, Subscriber, SubscriberFlags } from 'alien-signals';
import { ReactiveFlags } from "./contents" import { ReactiveFlags } from "./contents"
import { isFunction } from './utils';
const { const {
link, link,
propagate, propagate,
@ -238,9 +239,6 @@ export function unSignal<T>(signal: MaybeSignal<T> | Computed<T>): T {
return (isSignal(signal) ? signal.value : signal) as T; return (isSignal(signal) ? signal.value : signal) as T;
} }
export const isFunction = (val: unknown): val is Function =>
typeof val === 'function'
export function toValue<T>(source: MaybeSignalOrGetter<T>): T { export function toValue<T>(source: MaybeSignalOrGetter<T>): T {
return isFunction(source) ? source() : unSignal(source) return isFunction(source) ? source() : unSignal(source)
} }

@ -1,3 +1,16 @@
export * from "./core"; export * from "./core";
export * from "./deepSignal"; export * from "./deepSignal";
export * from "./watch" export * from "./watch"
export {
isArray,
isDate,
isFunction,
isMap,
isObject,
isPlainObject,
isPromise,
isRegExp,
isSet,
isString,
isSymbol,
} from "./utils"

@ -37,3 +37,5 @@ export const isPlainObject = (val: unknown): val is object =>
export const hasChanged = (value: any, oldValue: any): boolean => export const hasChanged = (value: any, oldValue: any): boolean =>
!Object.is(value, oldValue) !Object.is(value, oldValue)
export function NOOP() {}

@ -1,5 +1,5 @@
import { Computed, Effect, isSignal, Signal } from './core'; import { Computed, Effect, isSignal, Signal } from './core';
import { hasChanged, isArray, isMap, isObject, isPlainObject, isSet } from './utils'; import { hasChanged, isArray, isMap, isObject, isPlainObject, isSet, NOOP } from './utils';
import { isDeepSignal, isShallow } from "./deepSignal" import { isDeepSignal, isShallow } from "./deepSignal"
import { ReactiveFlags } from './contents'; import { ReactiveFlags } from './contents';
@ -69,9 +69,7 @@ export function watch(
getter = () => source.value getter = () => source.value
forceTrigger = isShallow(source) forceTrigger = isShallow(source)
} else if (isDeepSignal(source)) { } else if (isDeepSignal(source)) {
getter = () => { getter = () => signalGetter(source)
return signalGetter(source)
}
forceTrigger = true forceTrigger = true
} else if (isArray(source)) { } else if (isArray(source)) {
isMultiSource = true isMultiSource = true
@ -85,6 +83,14 @@ export function watch(
} }
}) })
} }
else {
getter = NOOP
if (process.env.NODE_ENV !== 'production') {
console.warn(
'Invalid watch source. Source must be a signal, a computed value !',
)
}
}
if (cb && deep) { if (cb && deep) {
const baseGetter = getter const baseGetter = getter
const depth = deep === true ? Infinity : deep const depth = deep === true ? Infinity : deep

Loading…
Cancel
Save