Skip to content

Commit

Permalink
feat(signal2): external types
Browse files Browse the repository at this point in the history
  • Loading branch information
alimd committed Jun 1, 2023
1 parent bd795ab commit 7b7238c
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions core/signal2/src/type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import type {MaybePromise} from '@alwatr/type';

/**
* Subscribe options type.
*/
export interface SubscribeOptions {
/**
* If true, the listener will be called only once.
*/
once?: true;

/**
* If true, the listener will be called before other.
*/
priority?: true;

/**
* If true, the listener will be defined disabled by default.
*/
disabled?: true;

/**
* If true, calls the listener (callback) with previous signal value (if dispatched before).
*/
receivePrevious?: boolean;

/**
* If defined, calls the listener (callback) with debounce.
*/
// debounce?: 'AnimationFrame' | number;
}

export type ListenerCallback<TValue> = (value: TValue) => MaybePromise<void>;

export interface ListenerObject<TValue> {
callback: ListenerCallback<TValue>;
options: SubscribeOptions;
}

export interface SubscribeResult {
unsubscribe: () => void;
}

0 comments on commit 7b7238c

Please sign in to comment.