/** * 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 { get(): T; subscribe(listener: (value: T, prevValue: T) => void): () => void; unsubscribe(listener: (value: T, prevValue: T) => void): void; } export interface Atom extends ReadOnlyAtom { set(newValue: T): void; update(recipe: (draft: Draft) => void): void; update(recipe: (draft: X) => void): void; } export declare class AtomValue implements Atom, 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) => 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(initialValue: T, options?: StateOptions): Atom; export declare function createState(): Atom; export interface AtomPersistentStorage { getItem(key: string): string | null; setItem(key: string, value: string): void; } export declare function _setAtomPersistentStorage(newStorage: AtomPersistentStorage): void; export declare function isAtom(value: any): value is Atom; export {}; //# sourceMappingURL=atom.d.ts.map