-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
adr 006 changes and implementation #1648
Conversation
🦋 Changeset detectedLatest commit: 4a95047 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
b02e6eb
to
5237e87
Compare
184e4ee
to
cf7f02d
Compare
15a6de6
to
3aebe88
Compare
35b93b6
to
b23ecb0
Compare
8a3e9ea
to
e017edc
Compare
4814556
to
9f18487
Compare
fae695a
to
d1730c1
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.
We are extremely close! I think that the requested changes are final
@turbocrime regarding the questions in the PR description, sharing my opinion:
no need for activating them immediately – users can always check the state an any time.
is it different from the previous question? don't really see the difference, so the answer remains
this could be useful – will save users at least one function call
probably no
this might be an unexpected UX. Maybe in the future we'll add some more wrappers or handlers to the service calls with some logic but I'd leave it as-is for now
+1 on this, could be here or we can create an issue for this and leave for later |
the purpose of a callback is to notify of state changes, but there are two locations with state- the client, and the provider. for instance consider this pattern:
now, the client has transitioned from a 'connected = undefined' state to a 'connected = true' state, but no callbacks were activated. the client is not explicitly holding an active port, but when queried will report its provider's 'true' connected status. its provider is connected, and no event has been emitted, and no transport has been constructed.
it is different from the previous question by the sequence of operations: callback is attached after event. consider this sequence
the callback added in 4 will likely never fire. i believe this is widely understood, and ok, but trying to confirm all details.
ok, will expose existing private method that performs this function. this does not save any calls, but rather provides the opportunity to conduct more function calls, and it adds another ambiguous/intermediate state.
the alternatives are
if the
ok, this will necessarily return
ok |
but we can create a PromiseClient that will return empty port when the client is not configured, aren't we? This way there's no need to return as for the other questions (about callbacks, for example) i don't have strong opinions, so i'd be ok with any implementation |
this is an option 4. which i avoided because it is likely confusing to the consumer
|
at some point, if the caller is doing something wrong, we have to throw. it is better to throw at the location of the problem, when the problem is noticed. creating broken outputs like that is essentially a null propagation error. we should enable developers to use this library correctly by rejecting conditions that are incorrect. i dislike that 'void' or 'undefined' are acceptable returns from many of these functions. it seemed very desired to we avoid things like 'undefined' return, but they've been added back now in response to discussion. simply returning 'undefined', when there is an explainable problem, obscures what's happening and is ultimately confusing rather than robust. |
@turbocrime alright, let's throw an error from the service creation. If one day we find a more neat solution to change the behavior, it won't be a breaking change |
with the addition of this check, web/packages/client/src/client.ts Lines 328 to 333 in 52e7c84
and the removal of the event type change, prax 11.13.1 is functional with all features of this ADR. prax must still be updated to support more than one connection within a document lifecycle, but that work is in prax-wallet/prax#134 |
questions answered
yes. an unconfigured client with callbacks will notify listeners when it attaches to a provider. this is how you expected it to function in your nextjs demo.
no. a caller who wishes to identify the present state must do so by checking the present state.
this is provided and termed
Given that the connect method now uses attach internally, this flow may be common, and is demonstrated in your nextjs example:
creating a service client before attaching to a provider will throw. this will prevent nonsensical use patterns, or use patterns creating subtle timeout issues or race conditions with configuration. notably: consumers should not use an unconfigured client to create a service client at a top-level scope and then export it.
|
notably, as it was requested that operations on a client with no configured provider should return undefined instead of throwing where reasonable, this implementation involves a field indicating a three-state true/false/undefined connection status, with undefined representing the connection state of a client which is not attached to a provider. i just want to point that out. |
52e7c84
to
10ceb33
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.
🎉🎉🎉
Co-Authored-By: the letter L <[email protected]>
* feat: add ADR-006 for web APIs and general description * adr 006 changes (#1647) * feat: updates from #1648 Co-Authored-By: the letter L <[email protected]> * fix: add some info * docstrings merge --------- Co-authored-by: the letter L <[email protected]> Co-authored-by: turbocrime <[email protected]>
befa59f
to
9bc3da3
Compare
6777138
to
4a95047
Compare
meeting suggestions in #1647suggestions available in adr doc in this pr
still removes react package, it would be broken by implementation
currently
implements PenumbraClient as a class with static and instance methods.
a class instance may be created without configuration, but must be configured with provider to connect.
an unconfigured client instance
.connect
methodquestions remainingshould an unconfigured client instance which possesses callbacks activate the callbacks immediately when a provider is configured with an event representing the new provider's present state, or wait until the provider emits a state change event?should a callback added to a client be immediately activated with an event representing the present state, or wait until the provider emits a state change event?should an existing unconfigured client instance provide a feature to select a provider without attempting connection?is it appropriate to throw creation of a service client when no provider is configured?is it appropriate to implicitly request a connection if a service client is created when a provider is configured but not connected?i'd like to add
when parsing the manifest, the client could either reformat the icon URLs to a fully-qualified path, or simply fetch them so they are available synchronously.