@gaubee/flow
Version:
启发于 kotlin 的 flow,针对 js/ts 开发人员设计的接口,通常可以作为一个事件管理器
30 lines • 1.1 kB
TypeScript
import type { PureEvent, PureEventFun, PureEventListenOptions, PureEventOff } from "@gaubee/util";
import { SharedFlow } from "./shared_flow.js";
export type StateFlowListenOptions = PureEventListenOptions & {
/** 监听的时候,是否立即执行 */
immediate?: boolean;
};
/**
* 带状态机的 SharedFlow
*/
export declare class StateFlow<T> extends SharedFlow<T> {
#private;
constructor(initialValue: T, by?: PureEvent<T>);
get value(): T;
set value(value: T);
/**
* 附加监听
* 同 watch
* @deprecated 使用 watch
*/
on(cb: PureEventFun<T>, options?: StateFlowListenOptions): PureEventOff;
/**
* 附加监听
* 可以自定义唯一索引 key,如果重复,会移除之前的监听
*/
watch(cb: PureEventFun<T>, options?: StateFlowListenOptions): PureEventOff;
watchImmediate(cb: PureEventFun<T>, options?: PureEventListenOptions): PureEventOff;
emit(value: T): Promise<void>;
}
export declare const stateFlow: <T>(initialValue: T, by?: any) => StateFlow<T>;
//# sourceMappingURL=state_flow.d.ts.map