socket.io-client
socket.io-client copied to clipboard
questions about the source-code
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.backoffis undefined sometimes? Are there actually times when it is not defined? - can the
serveClientoption 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 dothis.ondata.bind(this)(which is the same asManager.prototype.ondata.bind(this)) instead ofbind(this, "ondata")? One advantage of using native bind is that typescript will check that the types make sense. - Would these fields
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.