Conversation
9c89dca to
be37c73
Compare
e904f32 to
99bc8d7
Compare
bd9c430 to
fdd6da9
Compare
0569f2d to
d7e6984
Compare
d7e6984 to
907a6da
Compare
mcmire
left a comment
There was a problem hiding this comment.
Did a quick pass over this. I'll try to look at this more closely tomorrow.
|
I think we should note that this is for "client side" sending notifications to the server. I believe "server side" notifications end up being an event emitter which isnt in json-rpc-engine but |
mcmire
left a comment
There was a problem hiding this comment.
JsonRpcEngine sure is getting complicated isn't it 😅 Still, these seem like reasonable updates. LGTM.
| ```js | ||
| const engine = new JsonRpcEngine({ notificationHandler }); | ||
|
|
||
| // A notification is defined as a JSON-RPC request without an `id` property. |
There was a problem hiding this comment.
This seems like it could cause all of kinds of runtime bugs. Glad we're using TypeScript 😬
|
|
||
| const req: JsonRpcRequest<unknown> = { ...callerReq }; | ||
| // Handle notifications. | ||
| // We can't use isJsonRpcNotification here because that narrows callerReq to |
There was a problem hiding this comment.
I am not 100% sure on this, but my guess is that it's because there is no correlation between this._notificationHandler and the type of callerReq. If there is a way to tell TypeScript that when this_.notificationHandler is given then all requests must be notifications then this could work, but I'm not sure quite how to do that. This seems sufficient. I appreciate the comment!
|
@shanejonas not when I'm done with it 😎 |
This PR adds JSON-RPC 2.0-compliant notification handling for
JsonRpcEngine.idproperty.notificationHandler, is introduced. This parameter is a function that accepts JSON-RPC notification objects and returnsvoid | Promise<void>.JsonRpcEngine.handleis called, if anotificationHandlerexists, any request objects duck-typed as notifications will be handled as such. This means that:methodfield is not a string.handle()will beundefined.JsonRpcEngine.handleis called and nonotificationHandlerexists, notifications will be treated just like requests. This is the current behavior.