gritzko/swarm — pull request #6 by andreypopp (2014-07-15 14:47:46+00:00)
Title: Convert to CommonJS

This PR decomposes monolithic files into CommonJS modules. Please note that this PR is just an attempt to start a discussion and not to be merged as-is (for example, I didn't convert tests yet, though mainly because I didn't able to find a way to run them properly).

I think codebase decomposed into modular pieces is more readable and maintainable. This also helps to avoid circular dependencies and tight coupling between components and so makes code more cleaner, I believe.

CommonJS modules are clearly a de-facto standard now for a large scale client side development. Though there are downsides too. For example, you can't use swarm w/o preprocessing step which bundles all commonjs modules into a singe runnable file. Though that can be addressed by publishing built version of Swarm on bower and some CDNs.

Things changed:

* Swarm options are now kept in a separate `options` module. Some functions are provided to configure it, like `Swarm.setLocalhost(host)` and `Swarm.registerProtocolHandler(protocol, handler)`.

* There are two entry points in library, one for server side and one for browsers, both provide different initial configurations.

Example of using CommonJSified codebase — https://github.com/andreypopp/todomvc-flux-swarm