feat(host): export subscribeConnectionStatus - #295
Open
Imod7 wants to merge 2 commits into
Open
Conversation
📦 Bundle size impactComparing
Thresholds — warn: ≥10% or ≥5.0 KB · fail: ≥20% or ≥15.0 KB (bundled). Percentage only applies once the baseline is ≥ 10 KB. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds a function to
@parity/product-sdk-hostthat reports whether the app's channel to the hostcontainer is up. You pass a callback, it runs immediately with the current status and again on every
change, and it returns a function to stop listening. The status is
"connecting","connected"or"disconnected".The signal already existed in
@parity/truapi, reachable only by importing that lower level packagedirectly. This publishes it from the SDK.
Changes
packages/host/src/transport.tsaddssubscribeConnectionStatus, theHostConnectionStatustype,and
emitConnectionStatusfor tests. It also holds"disconnected"when the underlying signalreports
"connecting"after the channel has closed, and notifies subscribers whensetTruApiClientinjects or clears a client.
packages/host/src/index.tsexports the function and the type.packages/host/src/testing.tsre-exportsemitConnectionStatusand adds it toFakeHost, so aproduct can test its offline and reconnecting states. Breaking for anyone who writes their own object
of type
FakeHost, because the member is required.pending-changesets/host-subscribe-connection-status.mdis the changeset, minor for@parity/product-sdk-hostand@parity/product-sdk.Why these changes
coin-flip needs this to finish its migration and currently runs its own hook over
@novasamatech/host-api-wrapper. Landing it first means coin-flip never takes a direct dependency on@parity/truapi, and the signature matches its existing hook, so the change there is one import.The raw signal is wrong after a disconnect, so this corrects it rather than passing it through.
@parity/truapi0.7.0 never clears its cached client when the pipe closes, so the next subscriberreads
"connecting"from a dead client and every existing subscriber receives that value with no wayback. A route change after the host went away showed a spinner that never ended instead of an offline
state. An upstream fix should follow, and this correction can be removed then.
Testing
Before: 92 tests pass in the host package, 5 of them in
transport.ts.After: 102 pass, 15 in
transport.ts.Run from
product-sdk/: