socket.io-client icon indicating copy to clipboard operation
socket.io-client copied to clipboard

questions about the source-code

Open david-fong opened this issue 3 years ago • 0 comments

Background: I'm preparing a PR to add more typing information now that the repo is written in typescript (🎉). I was wondering if you can explain some things for me.

  • Why does the manager check for whether this.backoff is undefined sometimes? Are there actually times when it is not defined?
  • can the serveClient option for the manager ever be the empty string? If it should never be the empty string, we can use ?? instead of || when defaulting the option.
  • why use component-bind package instead of javascript's native Function.prototype.bind? Isn't it okay to do this.ondata.bind(this) (which is the same as Manager.prototype.ondata.bind(this)) instead of bind(this, "ondata")? One advantage of using native bind is that typescript will check that the types make sense.
  • Would these fields image ever need to be used outside of the Socket class? Would it be a good and safe idea to completely prevent code outside of the Socket class from accessing those fields? If so, we could use JavaScript private fields. But... this would be a breaking change, since any dependent packages accessing those fields would no longer be able to use them.

david-fong avatar Dec 06 '20 03:12 david-fong