Skip to content
This repository was archived by the owner on Nov 3, 2025. It is now read-only.

Commit 88f7e28

Browse files
committed
🐛 (createCanal) fix missing back subscription on instantiate
1 parent 8f24877 commit 88f7e28

2 files changed

Lines changed: 19 additions & 6 deletions

File tree

src/__tests__/createCanal.test.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,17 @@ describe('createCanal', () => {
164164
<Canal a />
165165
</BackContext.Provider>
166166
);
167+
// @ts-ignore
168+
testRenderer.root.children[0].instance.back$.subscribe(spy);
169+
back$.next({ target: null });
170+
expect(spy).toHaveBeenCalledWith({
171+
target: 'a'
172+
});
167173
testRenderer.update(
168174
<BackContext.Provider value={{ back$ }}>
169175
<Canal a b />
170176
</BackContext.Provider>
171177
);
172-
// @ts-ignore
173-
testRenderer.root.children[0].instance.back$.subscribe(spy);
174178
back$.next({ target: null });
175179
expect(spy).toHaveBeenCalledWith({
176180
target: 'b'

src/createCanal.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import React, { ComponentType, Component as ReactComponent } from 'react';
22
import { ViewStyle, View, StyleSheet, StyleProp } from 'react-native';
33
import { Observer } from 'mobx-react/native';
44
import { fromStream } from 'mobx-utils';
5-
import { Subject, Observable } from 'rxjs';
5+
import { Subject, Observable, ConnectableObservable } from 'rxjs';
66
import {
77
map,
88
distinctUntilChanged,
99
withLatestFrom,
10-
share
10+
publish
1111
} from 'rxjs/operators';
1212
import { Navigation } from './Navigation';
1313
import { last } from './utils/Array.last';
@@ -38,6 +38,8 @@ export const createCanal = <
3838
implements ICanal {
3939
constructor(props: WithBackContext<CanalComponentProps<Authorizations>>) {
4040
super(props);
41+
42+
this.back$.connect();
4143
const { style, backContext, ...nextAuthorizations } = props;
4244

4345
/**
@@ -108,7 +110,14 @@ export const createCanal = <
108110
)
109111
);
110112

111-
back$: Observable<IBackEvent> = this.props.backContext.back$.pipe(
113+
/**
114+
* @TODO Pipe operator cannot infer return type as ConnectableObservable.
115+
* See https://github.com/ReactiveX/rxjs/issues/2972.
116+
*/
117+
// @ts-ignore
118+
back$: ConnectableObservable<
119+
IBackEvent
120+
> = this.props.backContext.back$.pipe(
112121
withLatestFrom(this.progress$),
113122
map(([_, progress]) => {
114123
const currentStop = last(progress);
@@ -117,7 +126,7 @@ export const createCanal = <
117126
}
118127
return { target: null };
119128
}),
120-
share()
129+
publish()
121130
);
122131

123132
shouldComponentUpdate({

0 commit comments

Comments
 (0)