felangel / web_socket_client

A simple WebSocket client for Dart which includes automatic reconnection logic.
https://pub.dev/packages/web_socket_client
MIT License
150 stars 32 forks source link

refactor: Why is ConnectionState an abstact class and not an enum? #46

Closed rekire closed 4 months ago

rekire commented 4 months ago

Description

I was checking the documentation regarding the connection state (and I expected a stream btw). I noticed that the ConnectionState is an abstract class. It seems that there is a special handling for Disconnected. I think that should be some kind of error stream instead of part of an state.

Requirements

felangel commented 4 months ago

Hi @rekire 👋 ConnectionState is not an enum because the Disconnected state contains properties like the error, stackTrace, and code which are not applicable in other states. If there was an error stream then you'd need to handle listening to two streams which seems like it would negatively impact the developer experience. In addition, imo being disconnected is part of the connection state.

Closing for now but if you feel strongly about this please provide some additional context regarding what use-case you have and how these changes would improve your usage and I'm happy to take a closer look, thanks!