Skip to content

Commit

Permalink
fix: introduce AsyncComputed class and update return types in unstabl…
Browse files Browse the repository at this point in the history
…e_createAsyncComputed and unstable_useAsyncComputedValue functions
  • Loading branch information
Rajaniraiyn committed Dec 25, 2024
1 parent 1660937 commit a3f8c41
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Binary file modified bun.lockb
Binary file not shown.
15 changes: 11 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,20 @@ import {
signal as alienSignal,
unstable as alienUnstable,
Effect,
type Computed,
type Dependency,
type EffectScope,
type ISignal,
type IWritableSignal,
} from "alien-signals";
import { useEffect, useMemo, useState, useSyncExternalStore } from "react";

export declare class AsyncComputed<T = any> extends Computed {
get(): Promise<T>;
//@ts-expect-error
update(): Promise<boolean>;
}

/**
* Creates a writable Alien Signal.
*
Expand Down Expand Up @@ -106,12 +113,12 @@ export function createSignalScope(): EffectScope {
*
* @template T - The type of the computed value.
* @param {() => AsyncGenerator<Dependency, T>} getter - An async generator returning dependencies and ultimately a value.
* @returns {alienUnstable.AsyncComputed<T>} The created async computed signal.
* @returns {AsyncComputed<T>} The created async computed signal.
* @experimental
*/
export function unstable_createAsyncComputed<T>(
getter: () => AsyncGenerator<Dependency, T>,
): alienUnstable.AsyncComputed<T> {
): AsyncComputed<T> {
return alienUnstable.asyncComputed<T>(getter);
}

Expand Down Expand Up @@ -389,12 +396,12 @@ export function useSignalScope(): EffectScope {
* ```
*
* @template T - The type of the computed value.
* @param {alienUnstable.AsyncComputed<T>} alienAsyncComp - The async computed signal to read.
* @param {AsyncComputed<T>} alienAsyncComp - The async computed signal to read.
* @returns {T | undefined} The resolved value (or undefined if not yet resolved).
* @experimental
*/
export function unstable_useAsyncComputedValue<T>(
alienAsyncComp: alienUnstable.AsyncComputed<T>,
alienAsyncComp: AsyncComputed<T>,
): T | undefined {
const [value, setValue] = useState<T | undefined>(
alienAsyncComp.currentValue,
Expand Down

0 comments on commit a3f8c41

Please sign in to comment.