diff --git a/src/ObservableObject.ts b/src/ObservableObject.ts index 8320022c8..8925a8d16 100644 --- a/src/ObservableObject.ts +++ b/src/ObservableObject.ts @@ -30,6 +30,7 @@ import { } from './is'; import type { ChildNodeValue, + GetOptions, NodeValue, ObservableObject, ObservableState, @@ -783,7 +784,8 @@ export function extractFunctionOrComputed(node: NodeValue, obj: Record { + get: (node: NodeValue, options?: TrackingType | (GetOptions & UseSelectorOptions)) => { if (needsSelector()) { - return useSelector(() => get(node, track)); + return useSelector(() => get(node, options), isObject(options) ? options : undefined); } else { - return get(node, track); + return get(node, options); } }, }, }); } + +// Types: + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import type { GetOptions, ObservableBaseFns } from '@legendapp/state'; + +declare module '@legendapp/state' { + interface ObservableBaseFns { + get(options?: TrackingType | (GetOptions & { suspense?: boolean })): T; + } +} diff --git a/src/observableInterfaces.ts b/src/observableInterfaces.ts index a9cc48622..ae7614992 100644 --- a/src/observableInterfaces.ts +++ b/src/observableInterfaces.ts @@ -47,9 +47,12 @@ export interface MapGet | WeakMap> { get(): T; size: ObservableChild; } +export interface GetOptions { + shallow: boolean; +} export interface ObservableBaseFns { peek(): T; - get(trackingType?: TrackingType): T; + get(options?: TrackingType | GetOptions): T; onChange( cb: ListenerFn, options?: { trackingType?: TrackingType; initial?: boolean; immediate?: boolean; noArgs?: boolean },