Skip to content

Commit

Permalink
ensure Reactivity rerenders on duplicate events
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-smart committed Dec 4, 2024
1 parent 2d385a4 commit 8649d90
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/experimental/src/EventJournal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ export const makeMemory: Effect.Effect<typeof EventJournal.Service> = Effect.gen
const uncommittedRemotes: Array<RemoteEntry> = []
const uncommitted: Array<Entry> = []
for (const remoteEntry of options.entries) {
if (!byId.has(remoteEntry.entry.idString)) {
if (byId.has(remoteEntry.entry.idString)) {
if (remoteEntry.remoteSequence > remote.sequence) {
remote.sequence = remoteEntry.remoteSequence
}
Expand Down
28 changes: 20 additions & 8 deletions packages/experimental/src/Reactivity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,29 @@ export const make = Effect.sync(() => {
const results = yield* Mailbox.make<A, E>()
const runFork = yield* FiberHandle.makeRuntime<R>()

const handledEffect = Effect.matchCause(effect, {
onFailure(cause) {
results.unsafeDone(Exit.failCause(cause))
},
onSuccess(a) {
results.unsafeOffer(a)
let running = false
let pending = false
const handleExit = (exit: Exit.Exit<A, E>) => {
if (exit._tag === "Failure") {
results.unsafeDone(Exit.failCause(exit.cause))
} else {
results.unsafeOffer(exit.value)
}
})
if (pending) {
pending = false
run()
} else {
running = false
}
}

function run() {
runFork(handledEffect, { onlyIfMissing: true })
if (running) {
pending = true
return
}
running = true
runFork(effect).addObserver(handleExit)
}

yield* Scope.addFinalizer(
Expand Down

0 comments on commit 8649d90

Please sign in to comment.