Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 65bcecd2 authored by Daniel Jacob Chittoor's avatar Daniel Jacob Chittoor
Browse files

Split `wasAlreadyConnected` into query and command

wasAlreadyConnected() both checks state and mutates it, violating
command-query separation. The function name implies a pure query but
has a hidden side effect of marking the device as connected. This
pattern is error-prone and makes the code harder to reason about.

Split into two explicit methods:
  - isFirstConnection(): pure query, returns true if not yet connected
  - markAsConnected(): explicit state mutation

Update controller.manager.js to call both methods explicitly, making
the control flow clear at the call site.
parent 9ee8e76d
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -273,8 +273,8 @@ export class Controller {

  async onDeviceConnected() {
    const productName = this.deviceManager.getProductName();
    const wasAlreadyConnected = this.deviceManager.wasAlreadyConnected();
    if (!wasAlreadyConnected) {
    if (this.deviceManager.isFirstConnection()) {
      this.deviceManager.markAsConnected();
      this.view.updateData("product-name", productName);
      this.model = productName;
      WDebug.log("ControllerManager Model:", this.model);
+6 −6
Original line number Diff line number Diff line
@@ -34,12 +34,12 @@ export class DeviceManager {
    await this.downloader.init();
  }

  wasAlreadyConnected() {
    if (this.wasConnected == false) {
      this.wasConnected = true;
      return false;
  isFirstConnection() {
    return !this.wasConnected;
  }
    return true;

  markAsConnected() {
    this.wasConnected = true;
  }

  setResources(folder, steps) {