-
Notifications
You must be signed in to change notification settings - Fork 597
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
[WALL-25371] Remove RxJS from WalletLinkConnection #1018
Conversation
This reverts commit c3ae669.
|
||
import { ConnectionState, RxWebSocket } from './RxWebSocket'; | ||
import { ConnectionState, WalletLinkWebSocket } from './RxWebSocket'; |
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.
Should we rename this file name to WalletLinkWebSocket?
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.
yes indeed.
didn't make the change yet due to github diff issues. will address in a later pr.
🙌 Looks great! Will need to pull it down and test. I'll check it out on Monday! |
@@ -43,7 +43,6 @@ | |||
"eventemitter3": "^5.0.1", |
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.
dear reviewers,
recommend to turn on Hide whitespace
https://github.com/coinbase/coinbase-wallet-sdk/pull/1018/files?diff=split&w=1
ty!
a50f5cf
to
7ce57a7
Compare
5a5c823
to
d438aed
Compare
@@ -1,27 +1,29 @@ | |||
// Copyright (c) 2018-2023 Coinbase, Inc. <https://www.coinbase.com/> | |||
// Licensed under the Apache License, version 2.0 | |||
|
|||
import { BehaviorSubject, empty, Observable, of, Subject, throwError } from 'rxjs'; | |||
import { flatMap, take } from 'rxjs/operators'; | |||
import { ServerMessage } from './ServerMessage'; |
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.
nit: should we rename this file to be WebSocket
since we're no longer using RX?
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.
#1018 (comment)
@cb-jake yup. but then github considered it as a new file and made it hard to compare from the previous implementation. will rename the file as followup.
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.
that makes sense
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 looks good and testing seems to work. I think we should have someone with more rxjs experience should look at the PR before merging
|
||
let connected = false; | ||
switch (state) { | ||
case ConnectionState.DISCONNECTED: | ||
// if DISCONNECTED and not destroyed |
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.
Checking if it's intentional we don't skip the initial disconnect event. Potential risk of calling ws.connect()
too many times?
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.
for the record:
with rxjs subject, it used to emit a default value DISCONNECTED
whenever the observable was subscribed
by replacing it with callback listener, we expect connectionStateListener
only gets invoked when there’s actual state changes. so we don’t need skip(1)
for DISCONNECTED
await this.authenticate(); | ||
this.sendIsLinked(); | ||
this.sendGetSessionConfig(); | ||
connected = true; |
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.
Previously we would do 'distinctUntilChanged' - meaning we would only emit connected if it changes. So we wouldn't emit two Nevermind, I see true
events in a row. Just making sure this doesn't have a side effect?this.connected = connected
is below and correctly checks for distinct until changed.
} | ||
break; | ||
|
||
case ConnectionState.CONNECTED: |
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 were skipping 2 events before authenticating. Not sure why this was here before but something to verify -are we sure we're not calling authenticate twice?
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.
for ConnectionState.CONNECTED
check which used to have skip(2)
, i believe it was to ignore initial DISCONNECTED
and CONNECTING
states as the comment said. we don’t need this skipping anymore for this code block as we moved to simple switch syntax instead of individual rx subscription.
@@ -246,15 +219,14 @@ export class WalletLinkConnection { | |||
this.diagnostic?.log(EVENTS.STARTED_CONNECTING, { | |||
sessionIdHash: Session.hash(this.sessionId), | |||
}); | |||
this.ws.connect().subscribe(); | |||
this.ws.connect(); | |||
} | |||
|
|||
/** | |||
* Terminate connection, and mark as destroyed. To reconnect, create a new | |||
* instance of WalletSDKConnection | |||
*/ | |||
public destroy(): void { |
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 were calling unsubscribe
before which would clear the previous listeners. I don't see that happening anymore. Is there a possibility that the listeners will now get called after the connection is destroyed, for example through a race condition?
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.
* [WALL-25371] Remove RxJS WalletLinkConnection * authenticate * onceConnected onceLinked * remove connectionStateSubject * adding delay function to replace rxjs delay * applying ws.connectionState$ changes * remove delay func * comment * this.connected * replace this.onceConnected$ * replace linkedSubject * cleanup * refactor RxWebSocket class * fix tests * remove rxjs from test files * cleanup * ws.setIncomingDataListener * keep markUnseenEventsAsSeen as it used to be * implement request resolve mapping * fix tests * rename RxWebSocket -> WalletLinkWebSocket * Revert "rename RxWebSocket -> WalletLinkWebSocket" This reverts commit c3ae669. * rename only the class * remove rxjs package * duh * cleanup * reimplement this.linked update pipeline * separate out once***ed logic * cleanup * this.shouldFetchUnseenEventsOnConnect * cleanup
* [WALL-25371] Remove RxJS WalletLinkConnection * authenticate * onceConnected onceLinked * remove connectionStateSubject * adding delay function to replace rxjs delay * applying ws.connectionState$ changes * remove delay func * comment * this.connected * replace this.onceConnected$ * replace linkedSubject * cleanup * refactor RxWebSocket class * fix tests * remove rxjs from test files * cleanup * ws.setIncomingDataListener * keep markUnseenEventsAsSeen as it used to be * implement request resolve mapping * fix tests * rename RxWebSocket -> WalletLinkWebSocket * Revert "rename RxWebSocket -> WalletLinkWebSocket" This reverts commit c3ae669. * rename only the class * remove rxjs package * duh * cleanup * reimplement this.linked update pipeline * separate out once***ed logic * cleanup * this.shouldFetchUnseenEventsOnConnect * cleanup
Summary
Previous RxJS removal changes
#779
#969
#988
#992
How did you test your changes?
manual + unit tests
test.mov