Skip to content

Commit 839ff48

Browse files
authored
Return the StreamInterceptor so that methods can be chained (#31)
1 parent 26f0275 commit 839ff48

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

example/client/client.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import Sentencer from 'sentencer';
44
import { ExampleTwoRequest } from './example2_pb';
5-
import { ExampleServicePromiseClient, ExampleServiceClient } from './example_grpc_web_pb';
5+
import { ExampleServiceClient, ExampleServicePromiseClient } from './example_grpc_web_pb';
66
import { ExampleOneRequest, StreamRequest } from './example_pb';
77

88
const __DEV__ = true;
@@ -52,8 +52,17 @@ function exampleStream(isErr) {
5252
stream.on('error', console.log);
5353
}
5454

55+
function exampleStreamChain() {
56+
client.streamingExample(new StreamRequest())
57+
.on('data', res => {
58+
document.body.innerHTML += `<div>${res.getTime()}</div>`;
59+
})
60+
.on('status', console.warn)
61+
.on('error', console.error);
62+
}
63+
5564
exampleOne()
56-
exampleStream()
65+
exampleStreamChain()
5766
exampleStream(true)
5867
setInterval(exampleOne, 8000)
5968
setInterval(exampleTwo, 10000)

public/inject.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ window.__GRPCWEB_DEVTOOLS__ = function (clients) {
5656
}
5757
StreamInterceptor.prototype.on = function (type, callback) {
5858
this._callbacks[type] = callback;
59+
return this;
5960
}
6061
clients.map(client => {
6162
client.client_.rpcCall_ = client.client_.rpcCall;

0 commit comments

Comments
 (0)