Skip to content

Commit

Permalink
feat(effects): add isInit method
Browse files Browse the repository at this point in the history
  • Loading branch information
artalar committed Oct 20, 2023
1 parent 8ac256c commit 4a8aeb1
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/effects/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
atom,
Atom,
AtomCache,
AtomProto,
Expand Down Expand Up @@ -272,3 +273,12 @@ export const withAbortableSchedule = <T extends Ctx>(ctx: T): T => {
},
})
}

const initSetAtom = atom(
(ctx, state = new WeakSet<AtomProto>()) => state,
'initSetAtom',
)
export const isInit = (ctx: Ctx) => {
const set = ctx.get(initSetAtom)
return set.has(ctx.cause.proto) ? false : !!set.add(ctx.cause.proto)
}

1 comment on commit 4a8aeb1

@vercel
Copy link

@vercel vercel bot commented on 4a8aeb1 Oct 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.