websocket-rails/websocket-rails — pull request #165 by jtomaszewski (2013-12-01 19:54:20+00:00)
Title: Refactor *.coffee files. Add reconnect() method.

Okay, it's a bit huge pull request. I spent a couple of hours yesterday refactoring coffescript files, mainly because I wanted to introduce `.connect`, `.disconnect` and `.reconnect` methods (to handle any possible connection problems from user's side).

1) Don't use fat arrows, if it's not needed.

I think we [coffescripters] should avoid it (see discussions at google.com: "avoid fat arrows in coffescript"). Reading source code when some methods randomly have fat arrows and some don't, is often difficult to understand and easy to misunderstand.

2) Extract common methods and code from Websocket and HttpConnection to AbstractConnection adapter (much cleaner + DRY).

3) Move `.connection_id` from WebSocketRails dispatcher to WebSocketRails.AbstractConnection. `.connection_id` is still also bound to events and channels.

This is because the connection ID should have its' own ID, not the dispatcher. Events and channels have also their connection_id bound because they are sent when they are constructed, so they are bound to "one connection".

With one exception: events can be resent, with their connection_id being updated then.

4) Add `.close()` method to AbstractConnection.

5) Add `.connect()`, `.disconnect()` and `.reconnect()` method to WebSocketRails.

6) Refactor some specs to make them easier to read and more DRY.

In summary, I didn't change any public methods like .trigger() or .bind(), so your production code should still work with the new js code after this commit.