Skip to content

Commit

Permalink
Remove "created" state
Browse files Browse the repository at this point in the history
Sarus will try to connect automatically in the constructor, so it is not
necessary to distinguish between "created" and "connecting".
  • Loading branch information
justuswilhelm committed Jan 2, 2024
1 parent 3be37fc commit 63690e7
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,24 +117,27 @@ export default class Sarus {
ws: WebSocket | undefined;
/*
* Track the current state of the Sarus object. See the diagram below.
* connect() this.ws.onopen
* ┌───────┐ │ ┌──────────┐ │ ┌─────────┐
* │created│─┴─►│connecting│──────┴───►│connected│ ◄───────────────────┐
* └───────┘ └──────────┘ └─────────┘ │
* disconnect() │ ▲ │ │
* ┌────────────────────────────────┘ │ │ this.ws.onclose │
* ▼ │ ▼ │
* ┌────────────┐ connect() │ ┌──────┐ │
* │disconnected│──────────────────────────┘ │closed│ ─────────────────┘
* └────────────┘ └──────┘ this.reconnect()
*
* reconnect() ┌──────┐
* ┌───────────────────────────────│closed│
* │ └──────┘
* │ ▲
* ▼ │ this.ws.onclose
* ┌──────────┐ this.ws.onopen ┌───┴─────┐
* │connecting├───────────────────────►│connected│
* └──────────┘ └───┬─────┘
* ▲ │ disconnect()
* │ ▼
* │ reconnect() ┌────────────┐
* └─────────────────────────────┤disconnected│
* └────────────┘
*
* connect(), disconnect() are generally called by the user
*
* this.reconnect() is called internally when automatic reconnection is
* enabled, but can also be called by the user
*/
state: "created" | "connecting" | "connected" | "disconnected" | "closed" =
"created";
state: "connecting" | "connected" | "disconnected" | "closed" = "connecting";

constructor(props: SarusClassParams) {
// Extract the properties that are passed to the class
Expand Down

0 comments on commit 63690e7

Please sign in to comment.