-
-
Notifications
You must be signed in to change notification settings - Fork 62
Conversation
9c89dca
to
be37c73
Compare
e904f32
to
99bc8d7
Compare
bd9c430
to
fdd6da9
Compare
0569f2d
to
d7e6984
Compare
d7e6984
to
907a6da
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
.id
property.notificationHandler
, is introduced. This parameter is a function that accepts JSON-RPC notification objects and returnsvoid | Promise<void>
.JsonRpcEngine.handle
is called, if anotificationHandler
exists, any request objects duck-typed as notifications will be handled as such. This means that:method
field is not a string.handle()
will beundefined
.JsonRpcEngine.handle
is called and nonotificationHandler
exists, notifications will be treated just like requests. This is the current behavior.