GoodDAPP icon indicating copy to clipboard operation
GoodDAPP copied to clipboard

(Chore) User rxjs to aggregate online status in internetConnection.js

Open serdiukov-o-nordwhale opened this issue 4 years ago • 0 comments

if we have a few streams of events (connect-disconnect) better to use use rxjs to aggregate the states (with ‘all’) condition

  • [ ] as useXXXConnection hooks haven’t used anywhere except internet connection, we’ll remove them. Instead we’ll define an _.once-wrapped factories returning behavior subjects (with initial state = false)
  • [ ] in internet connection we’ll define observable which arrgerates all source streams producing logical AND of the latest values emited (e.g. if at least once connection failed -> show dialog)
  • [ ] we’ll add some ref containing the state is dialog shown or not
  • [ ] then we just subscribing to observable on mount, returning () => subscription.unsubscribe() as cancel hook. on subsription we’re checking the aggregates status, showing dialog if false and dialog isn’t shown, hiding dialog if shown and status true
  • [ ] we have to add some conditional debounce to the aggregated observable. true state should be emited immediately. false should be debounced for some ms, if during them state becomes true, the transitional false state houldn't be emited

serdiukov-o-nordwhale avatar Jul 29 '20 10:07 serdiukov-o-nordwhale