Skip to content

Commit

Permalink
Add in integrations
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed Dec 27, 2024
1 parent 1f272d1 commit 30a196b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ declare class Signal<T = any> {
set value(value: T);
}

interface SignalOptions<T = any> {
export interface SignalOptions<T = any> {
watched: (this: Signal<T>) => void;
unwatched: (this: Signal<T>) => void;
}
Expand Down
10 changes: 7 additions & 3 deletions packages/preact/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
Signal,
type ReadonlySignal,
untracked,
SignalOptions,
} from "@preact/signals-core";
import {
VNode,
Expand Down Expand Up @@ -362,10 +363,13 @@ Component.prototype.shouldComponentUpdate = function (
return false;
};

export function useSignal<T>(value: T): Signal<T>;
export function useSignal<T>(value: T, options?: SignalOptions<T>): Signal<T>;
export function useSignal<T = undefined>(): Signal<T | undefined>;
export function useSignal<T>(value?: T) {
return useMemo(() => signal<T | undefined>(value), []);
export function useSignal<T>(value?: T, options?: SignalOptions<T>) {
return useMemo(
() => signal<T | undefined>(value, options as SignalOptions),
[]
);
}

export function useComputed<T>(compute: () => T) {
Expand Down
10 changes: 7 additions & 3 deletions packages/react/runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
effect,
Signal,
ReadonlySignal,
SignalOptions,
} from "@preact/signals-core";
import {
useRef,
Expand Down Expand Up @@ -384,10 +385,13 @@ export function useSignals(usage?: EffectStoreUsage): EffectStore {
return _useSignalsImplementation(usage);
}

export function useSignal<T>(value: T): Signal<T>;
export function useSignal<T>(value: T, options?: SignalOptions<T>): Signal<T>;
export function useSignal<T = undefined>(): Signal<T | undefined>;
export function useSignal<T>(value?: T) {
return useMemo(() => signal<T | undefined>(value), Empty);
export function useSignal<T>(value?: T, options?: SignalOptions<T>) {
return useMemo(
() => signal<T | undefined>(value, options as SignalOptions),
Empty
);
}

export function useComputed<T>(compute: () => T): ReadonlySignal<T> {
Expand Down

0 comments on commit 30a196b

Please sign in to comment.