snowglobe icon indicating copy to clipboard operation
snowglobe copied to clipboard

`Stage` and `ActiveClient` ergonomics

Open 3mcd opened this issue 2 years ago • 0 comments

Getting the ActiveClient instance from a client is a little hairy and error-prone. You have to do stuff like:

if (client.state() === StageState.Ready) {
  client.stage().ready!...
}

Where we have to manually assert the presence of the ready property. We could take advantage of a union type/type narrowing to make this more intuitive and "safer".

Furthermore, getting deeply nested properties off of ActiveClient and company can be really nasty, e.g.

mockClientServer.client1.stage().ready!.timekeepingSimulations.stepper
          .lastReceivedSnapshotTimestamp!

By the looks of it, we didn't port over a few methods that would make this a bit cleaner, like this one from ready.rs:

    pub fn last_received_snapshot_timestamp(&self) -> &Option<Timestamp> {
        &self
            .0
            .borrow()
            .timekeeping_simulations
            .last_received_snapshot_timestamp
    }

The equivalent in snowglobe would let us rewrite the above TypeScript snippet as:

mockClientServer.client1.stage().ready!.lastReceivedSnapshotTimestamp()

3mcd avatar Nov 13 '21 01:11 3mcd