Skip to content

Commit 5b5b138

Browse files
volivajosepot
authored andcommitted
fix(connectObservable): fix updates on more than one component
1 parent 9e880c9 commit 5b5b138

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/internal/react-enhancer.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ const reactEnhancer = <T>(
1111
delayTime: number,
1212
): BehaviorObservable<T> => {
1313
let finalizeLastUnsubscription = noop
14-
let latestValue = EMPTY_VALUE
1514
const result = new Observable<T>(subscriber => {
1615
let isActive = true
16+
let latestValue = EMPTY_VALUE
1717
const subscription = source$.subscribe({
1818
next(value) {
1919
if (
@@ -97,7 +97,6 @@ const reactEnhancer = <T>(
9797
}
9898

9999
if (value !== EMPTY_VALUE) {
100-
latestValue = value
101100
return (valueResult = { type: "v", payload: value })
102101
}
103102

src/internal/useObservable.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@ const SUSP: "s" = "s"
88
type Action = "e" | "v" | "s"
99

1010
const reducer = (
11-
_: { type: Action; payload: any },
11+
current: { type: Action; payload: any },
1212
action: { type: Action; payload: any },
1313
) => {
1414
if (action.type === ERROR) {
1515
throw action.payload
1616
}
17-
return action
17+
return Object.is(current.payload, action.payload) &&
18+
current.type === action.type
19+
? current
20+
: action
1821
}
1922

2023
const init = (source$: BehaviorObservable<any>) => source$.getValue()

0 commit comments

Comments
 (0)