rough-stuff / rough-notation

Create and animate hand-drawn annotations on a web page
https://roughnotation.com/
MIT License
8.65k stars 209 forks source link

Redundant statement in `RoughAnnotationImpl.show()` #71

Open ryan-di opened 2 years ago

ryan-di commented 2 years ago

Given that the AnnotationState is

type AnnotationState = 'unattached' | 'not-showing' | 'showing';

and when we call the private attach() method, we first check if the state is 'unattached'

private attach() {
  if (this._state === 'unattached' && this._e.parentElement) {
    // ...
  }
}

I think the this.attach() statement in the 'not-showing' case is redundant.

show(): void {
  switch (this._state) {
    case 'unattached':
      // ...
    case 'showing':
      // ...
    case 'not-showing':
      this.attach();
      if (this._svg) {
        this.render(this._svg, false);
      }
      break;
  }
}

Not sure if I'm missing anything : )

pshihn commented 2 years ago

You're probably right. It's redundant but benign as well. I'll have to think of why this was added. Wish I had commented the code :)