UNPKG

flipper-plugin

Version:

Flipper Desktop plugin SDK and components

53 lines 2.06 kB
/** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * * @format */ import { Draft } from 'immer'; import { Persistable } from '../plugin/PluginBase'; export interface ReadOnlyAtom<T> { get(): T; subscribe(listener: (value: T, prevValue: T) => void): () => void; unsubscribe(listener: (value: T, prevValue: T) => void): void; } export interface Atom<T> extends ReadOnlyAtom<T> { set(newValue: T): void; update(recipe: (draft: Draft<T>) => void): void; update<X extends T>(recipe: (draft: X) => void): void; } export declare class AtomValue<T> implements Atom<T>, Persistable { value: T; listeners: ((value: T, prevValue: T) => void)[]; constructor(initialValue: T); get(): T; set(nextValue: T): void; deserialize(value: T): void; serialize(): any; update(recipe: (draft: Draft<T>) => void): void; notifyChanged(prevValue: T): void; subscribe(listener: (value: T, prevValue: T) => void): () => void; unsubscribe(listener: (value: T, prevValue: T) => void): void; } type StateOptions = { /** * Should this state persist when exporting a plugin? * If set, the atom will be saved / loaded under the key provided */ persist?: string; /** * Store this state in local storage, instead of as part of the plugin import / export. * State stored in local storage is shared between the same plugin * across multiple clients/ devices, but not actively synced. */ persistToLocalStorage?: boolean; }; export declare function createState<T>(initialValue: T, options?: StateOptions): Atom<T>; export declare function createState<T>(): Atom<T | undefined>; export declare function isAtom(value: any): value is Atom<any>; export declare function useValue<T>(atom: ReadOnlyAtom<T>): T; export declare function useValue<T>(atom: ReadOnlyAtom<T> | undefined, defaultValue: T): T; export {}; //# sourceMappingURL=atom.d.ts.map