Skip to content

Commit

Permalink
fix(connectObservable): fix updates on more than one component
Browse files Browse the repository at this point in the history
  • Loading branch information
voliva authored and josepot committed Jul 14, 2020
1 parent 9e880c9 commit 5b5b138
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
3 changes: 1 addition & 2 deletions src/internal/react-enhancer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ const reactEnhancer = <T>(
delayTime: number,
): BehaviorObservable<T> => {
let finalizeLastUnsubscription = noop
let latestValue = EMPTY_VALUE
const result = new Observable<T>(subscriber => {
let isActive = true
let latestValue = EMPTY_VALUE
const subscription = source$.subscribe({
next(value) {
if (
Expand Down Expand Up @@ -97,7 +97,6 @@ const reactEnhancer = <T>(
}

if (value !== EMPTY_VALUE) {
latestValue = value
return (valueResult = { type: "v", payload: value })
}

Expand Down
7 changes: 5 additions & 2 deletions src/internal/useObservable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ const SUSP: "s" = "s"
type Action = "e" | "v" | "s"

const reducer = (
_: { type: Action; payload: any },
current: { type: Action; payload: any },
action: { type: Action; payload: any },
) => {
if (action.type === ERROR) {
throw action.payload
}
return action
return Object.is(current.payload, action.payload) &&
current.type === action.type
? current
: action
}

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

0 comments on commit 5b5b138

Please sign in to comment.