@cfcs/core
Version:
Write once, create framework components that supports React, Vue, Svelte, and more.
46 lines (45 loc) • 1.14 kB
TypeScript
/**
* cfcs
* Copyright (c) 2022-present NAVER Corp.
* MIT license
*/
import Component from "@egjs/component";
interface EmitterEvents<Value> {
update: (value: Value, prevValue: Value) => void;
}
/**
* Creates a mutable ref object. You can access the `.current` value and detect the value change through `.subscribe`.
* @category Reactive
* @see observe
*/
export declare class Observer<Value = any> {
protected _current: Value;
protected _emitter: Component<EmitterEvents<Value>>;
/**
*
*/
constructor(value?: Value);
/**
* return the current value.
*/
get current(): Value;
set current(value: Value);
/**
* When the current value changes, the callback function is called.
*/
subscribe(callback: (value: Value, prevValue: Value) => void): this;
/**
* Cancel the registered subscription through callback.
*/
unsubscribe(callback?: (value: Value, prevValue: Value) => void): this;
protected _setCurrent(value: Value): void;
/**
* @hidden
*/
toString(): string;
/**
* @hidden
*/
valueOf(): Value;
}
export {};