(Close to first 1.0 release)
Total rewrite of internals, but the API is almost the same.
- Add promise pattern (in addition to callback)*
- Add requestMessage to response/resolve callback (Tracked version)*
- Add full tests for all features, including full flow test.
- Removed subscribeQuery**
*Full track for handling of multiple of (the same or different) requests, so it's possible to use Promise.all etc.
// before: (and now! you can still do it this way)
bridge.sendQuery({ name, payload, onSuccess, onError })
// new option:
const response = await bridge.sendQuery({
name,
payload,
onSuccess,
onError,
})
// new option tracked:
const { response, request, responseMessage, requestMessage } =
await bridge.sendQueryTracked({
name,
payload,
onSuccess,
onError,
})
- Export MessageBridgeService has been removed (it was an alias for SignalRMessageBridgeService)
Use SignalRMessageBridgeService, WebSocketMessageBridgeService or ClientSideMessageBridgeService instead.
Almost no changes to the base: sendQuery, sendCommand, sendEvent, subscribeEvent
- onSuccess and onError methods are identical to the new tracked versions: RequestResponse<TRequest,TResponse>)
// before
bridge.sendQuery({
name,
payload,
onSuccess(response, responseMsg) {},
})
// after
bridge.sendQuery({
name,
payload,
onSuccess(response, { response, request, responseMsg, requestMsg }) {},
})
// or the new tracked:
bridge.sendQueryTracked({
name,
payload,
onSuccess({ response, request, responseMsg, requestMsg }) {},
})
// or the new tracked promise pattern:
const { response, request, responseMsg, requestMsg } = await bridge.sendQueryTracked({
name,
payload,
})
- subscribeQuery is removed !
**subscribeQuery was more or less unnecessary abstraction of subscribeEvent, and it do not support the new promise pattern. There are en example in the example folder for subscribe query is needed
-
"helper" (static methods, createMessage etc..) has been moved to a separate file (Not part of the class anymore)
-
Message is no longer a class, but an typescript type
Optimize Message by removing "class" version and only use interface (typescript type).
Notes:
trackId is optional but it will be create by createMessage, createCommandMessage and createQueryMessage. (Helper methods)
You can still create the id, but it's not recommended.
The trackId must be unique for each message, and is generated by the createMessage helper method. (Using 'uuid' module)
If you need the message (fx its trackId) before it's sent:
// Normal use
bridge.sendCommand({ name, payload })
// If trackId is needed before sent (Or other properties from the created message)
const msg = createCommandMessage({ name, payload, module })
bridge.sendMessage({
requestMessage: msg,
})
Almost all code is rewritten, so if you have extended the base class, there are a lot of changes.
// Take a look at the base, but it's important to call super.methodName()
// for most of the protected methods, at least for the ones that are called:
onConnect()
onError()
onClose()
See git history for changes before 0.2.0