mirror of
https://github.com/littensy/charm.git
synced 2026-10-20 17:51:37 +00:00
* feat: allow conditional dependencies * docs: remove conditional deps warnings * fix: allow nested captures * docs: add dev flag * fix: `try()` uses pcall if passed `finally()` * docs: interval is optional * docs: update readme * docs: add client/server tags
43 lines
1.1 KiB
Text
43 lines
1.1 KiB
Text
export type Set<T> = { [T]: true }
|
|
|
|
export type WeakMap<K, V> = typeof(setmetatable({} :: { [K]: V }, { __mode = "k" }))
|
|
|
|
--[=[
|
|
A primitive state container that can be read from and written to. When the
|
|
state changes, all subscribers are notified.
|
|
|
|
@param state The next state or a function that produces the next state.
|
|
@return The current state, if no arguments are provided.
|
|
]=]
|
|
export type Atom<T> = (() -> T) & (state: T | (T) -> T) -> T
|
|
|
|
--[=[
|
|
A function that depends on one or more atoms and produces a state. Can be
|
|
used to derive state from atoms.
|
|
|
|
@template State The type of the state.
|
|
@return The current state.
|
|
]=]
|
|
export type Molecule<T> = () -> T
|
|
|
|
--[=[
|
|
Optional configuration for creating an atom.
|
|
]=]
|
|
export type AtomOptions<T> = {
|
|
--[=[
|
|
A function that determines whether the state has changed. By default,
|
|
a strict equality check (`===`) is used.
|
|
]=]
|
|
equals: (prev: T, next: T) -> boolean,
|
|
}
|
|
|
|
--[=[
|
|
A payload that can be sent from the server to the client to synchronize
|
|
state between the two.
|
|
]=]
|
|
export type SyncPayload = {
|
|
type: "patch" | "init",
|
|
data: { [any]: any },
|
|
}
|
|
|
|
return nil
|