Skip to content

Commit afc2753

Browse files
Merge pull request #17 from FormidableLabs/fix-filtering
Add forwarding of devtools ops
2 parents dd8502c + a87f73c commit afc2753

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/exchange.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { map, pipe, tap, toPromise, take, filter } from "wonka";
1+
import { map, pipe, tap, toPromise, take, filter, merge, share } from "wonka";
22
import {
33
Exchange,
44
Client,
@@ -36,15 +36,27 @@ export const devtoolsExchange: Exchange = ({ client, forward }) => {
3636
sendToContentScript({ type: "init" });
3737

3838
return ops$ => {
39-
return pipe(
40-
ops$,
41-
map(addOperationContext),
42-
filter(o => !o.context.meta || o.context.meta.source !== "Devtools"),
39+
const sharedOps$ = pipe(ops$, map(addOperationContext), share);
40+
41+
const isDevtoolsOp = (o: Operation) =>
42+
Boolean(o.context.meta && o.context.meta.source === "Devtools");
43+
44+
const appOps$ = pipe(
45+
sharedOps$,
46+
filter(o => !isDevtoolsOp(o)),
4347
tap(handleOperation),
4448
forward,
4549
map(addOperationResponseContext),
4650
tap(handleOperation)
4751
);
52+
53+
const devtoolsOps$ = pipe(
54+
sharedOps$,
55+
filter(o => isDevtoolsOp(o)),
56+
forward
57+
);
58+
59+
return merge([appOps$, devtoolsOps$]);
4860
};
4961
};
5062

0 commit comments

Comments
 (0)