Skip to content

Commit 8041aed

Browse files
committed
fix Rx.debounce behaviour
1 parent 9537cd5 commit 8041aed

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

.changeset/light-pots-itch.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@effect-rx/rx": patch
3+
---
4+
5+
fix Rx.debounce behaviour

packages/rx/src/Rx.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,7 +1268,7 @@ export const debounce: {
12681268
})
12691269
get.subscribe(self, function(val) {
12701270
value = val
1271-
if (timeout) return
1271+
if (timeout) clearTimeout(timeout)
12721272
timeout = setTimeout(update, millis)
12731273
})
12741274
return value
@@ -1349,9 +1349,10 @@ export const searchParam = (name: string): Writable<string> =>
13491349
(ctx, value: string) => {
13501350
searchParamState.updates.set(name, value)
13511351
ctx.setSelf(value)
1352-
if (!searchParamState.timeout) {
1353-
searchParamState.timeout = setTimeout(updateSearchParams, 500)
1352+
if (searchParamState.timeout) {
1353+
clearTimeout(searchParamState.timeout)
13541354
}
1355+
searchParamState.timeout = setTimeout(updateSearchParams, 500)
13551356
}
13561357
)
13571358

0 commit comments

Comments
 (0)