Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: synchronous atomEffect #53

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
move AtomWithEffect type
dai-shi authored and dmaskasky committed Jan 23, 2025
commit 2bb34f1539e1f1a36fcdff3252f8b044324fd9d7
3 changes: 0 additions & 3 deletions src/atomEffect.ts
Original file line number Diff line number Diff line change
@@ -8,9 +8,6 @@ export type Effect = (
get: GetterWithPeek,
set: SetterWithRecurse
) => void | Cleanup
export type AtomWithEffect<T extends Atom<unknown> = Atom<void>> = T & {
effect: Effect
}

type Ref = {
get: GetterWithPeek
4 changes: 3 additions & 1 deletion src/withAtomEffect.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import type { Atom } from 'jotai/vanilla'
import type { AtomWithEffect, Effect } from './atomEffect'
import type { Effect } from './atomEffect'
import { atomEffect } from './atomEffect'

type AtomWithEffect<T extends Atom<unknown>> = T & { effect: Effect }

export function withAtomEffect<T extends Atom<unknown>>(
targetAtom: T,
effect: Effect