Skip to content

Commit

Permalink
update use observable to return unsub function (#471)
Browse files Browse the repository at this point in the history
  • Loading branch information
texuf authored Jul 26, 2024
1 parent 7d01612 commit 4b5acea
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/react-sdk/src/useObservable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ export function useObservable<T>(
if (!observable) {
return
}
const subscription = observable.subscribe(onSubscribe, {
const unsub = observable.subscribe(onSubscribe, {
fireImediately: opts?.fireImmediately,
})
return () => subscription.unsubscribe(onSubscribe)
return unsub
}, [opts, observable, onSubscribe])

const data = useMemo(() => {
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk/src/observable/observable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class Observable<T> {
subscribe(
subscriber: (newValue: T) => void,
opts: { fireImediately?: boolean; once?: boolean; condition?: (value: T) => boolean } = {},
): this {
): () => void {
const sub = {
id: this._nextId++,
fn: subscriber,
Expand All @@ -37,7 +37,7 @@ export class Observable<T> {
if (opts.fireImediately) {
this._notify(sub, this.value)
}
return this
return () => this.unsubscribe(subscriber)
}

when(
Expand Down

0 comments on commit 4b5acea

Please sign in to comment.