mirror of
https://github.com/littensy/charm.git
synced 2026-10-21 11:44:08 +00:00
feat!: replace split with mapAtom
This commit is contained in:
parent
fc3cd6d9ad
commit
4d4979daa9
11 changed files with 188 additions and 245 deletions
|
|
@ -11,7 +11,7 @@ type AtomInternal<T> = {
|
|||
export type Atom<T> = (() -> T) & ((state: T | ((T) -> T)) -> ()) & {
|
||||
get: ((self: Atom<T>) -> T) & (<Result>(self: Atom<T>, selector: (T) -> Result) -> Result),
|
||||
set: (self: Atom<T>, state: T | ((T) -> T)) -> (),
|
||||
memo: (self: Atom<T>, equalityFn: (previous: T, current: T) -> boolean) -> Atom<T>,
|
||||
memo: (self: Atom<T>, areEqual: (previous: T, current: T) -> boolean) -> Atom<T>,
|
||||
writable: (self: Atom<T>, onSet: ((update: T, previous: T) -> T?) & (update: T, previous: T) -> ()) -> Atom<T>,
|
||||
readonly: (self: Atom<T>) -> ReadonlyAtom<T>,
|
||||
named: (self: Atom<T>, label: string) -> Atom<T>,
|
||||
|
|
@ -20,7 +20,7 @@ export type Atom<T> = (() -> T) & ((state: T | ((T) -> T)) -> ()) & {
|
|||
|
||||
export type ReadonlyAtom<T> = (() -> T) & {
|
||||
get: ((self: ReadonlyAtom<T>) -> T) & (<Result>(self: ReadonlyAtom<T>, selector: (T) -> Result) -> Result),
|
||||
memo: (self: ReadonlyAtom<T>, equalityFn: (previous: T, current: T) -> boolean) -> ReadonlyAtom<T>,
|
||||
memo: (self: ReadonlyAtom<T>, areEqual: (previous: T, current: T) -> boolean) -> ReadonlyAtom<T>,
|
||||
writable: ((self: Atom<T>) -> Atom<T>)
|
||||
& ((self: Atom<T>, onSet: ((update: T, previous: T) -> T?) & (update: T, previous: T) -> ()) -> Atom<T>),
|
||||
readonly: (self: ReadonlyAtom<T>) -> ReadonlyAtom<T>,
|
||||
|
|
@ -81,8 +81,8 @@ local function atom<State>(state: State): Atom<State>
|
|||
end
|
||||
end
|
||||
|
||||
function atom:memo(equalityFn: (State, State) -> boolean): Atom<State>
|
||||
equals = equalityFn
|
||||
function atom:memo(areEqual: (State, State) -> boolean): Atom<State>
|
||||
equals = areEqual
|
||||
return self
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue