-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add atom shims and export atomState type
- Loading branch information
David Maskasky
committed
Sep 24, 2024
1 parent
7008857
commit 914d987
Showing
5 changed files
with
47 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,7 @@ | ||
import type { Atom, WritableAtom } from '../../jotai'; | ||
import type { Atom, WritableAtom } from '../../jotai' | ||
|
||
export type AnyValue = unknown; | ||
export type AnyError = unknown; | ||
export type AnyAtom = Atom<AnyValue>; | ||
export type AnyWritableAtom = WritableAtom<AnyValue, unknown[], unknown>; | ||
export type OnUnmount = () => void; | ||
|
||
/** | ||
* Mutable atom state, | ||
* tracked for both mounted and unmounted atoms in a store. | ||
*/ | ||
export type AtomState<Value = AnyValue> = { | ||
/** | ||
* Map of atoms that the atom depends on. | ||
* The map value is the epoch number of the dependency. | ||
*/ | ||
readonly d: Map<AnyAtom, number>; | ||
|
||
/** | ||
* Set of atoms with pending promise that depend on the atom. | ||
* | ||
* This may cause memory leaks, but it's for the capability to continue promises | ||
*/ | ||
readonly p: Set<AnyAtom>; | ||
|
||
/** The epoch number of the atom. */ | ||
n: number; | ||
|
||
/** | ||
* Object to store mounted state of the atom. | ||
* | ||
* State tracked for mounted atoms. An atom is considered "mounted" if it has a | ||
* subscriber, or is a transitive dependency of another atom that has a | ||
* subscriber. | ||
* | ||
* The mounted state of an atom is freed once it is no longer mounted. | ||
* | ||
* only available if the atom is mounted | ||
*/ | ||
m?: { | ||
/** Set of listeners to notify when the atom value changes. */ | ||
readonly l: Set<() => void>; | ||
|
||
/** Set of mounted atoms that the atom depends on. */ | ||
readonly d: Set<AnyAtom>; | ||
|
||
/** Set of mounted atoms that depends on the atom. */ | ||
readonly t: Set<AnyAtom>; | ||
|
||
/** Function to run when the atom is unmounted. */ | ||
u?: OnUnmount; | ||
}; | ||
|
||
/** Atom value */ | ||
v?: Value; | ||
|
||
/** Atom error */ | ||
e?: AnyError; | ||
}; | ||
|
||
export type GetAtomState = <Value>( | ||
atom: Atom<Value>, | ||
originAtomState?: AtomState, | ||
) => AtomState<Value>; | ||
|
||
// internal & unstable type | ||
export type StoreArgs = readonly [ | ||
getAtomState: GetAtomState, | ||
// possible other arguments in the future | ||
]; | ||
export type AnyValue = unknown | ||
export type AnyError = unknown | ||
export type AnyAtom = Atom<AnyValue> | ||
export type AnyWritableAtom = WritableAtom<AnyValue, unknown[], unknown> | ||
export type OnUnmount = () => void |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters