hypothesis/h — pull request #1693 by aron (2014-11-17 23:32:07+00:00)
Title: Refactor Chrome Extension

This PR takes #1665 and build upon it to add:

* A more modular approach to working with the Chrome extension, there are now several components that can be instantiated individually (and tested) without running background.js.
* Unit tests with their own karma config.
* The beginnings of some documentation.
* An "errored" state (no proper handling of this yet though).

There are now four separate components, the `HypothesisChromeExtension` which sets up all the components and binds the event listeners. A `TabStore` which deals with persisting the tab state to local storage. A `TabState` which keeps track of all the tabs and which are active/inactive. A `BrowserAction` which just ensures that the button is displayed correctly and finally a `SidebarInjector` which deals with actually injecting the sidebar into various environments. All of these have their dependencies passed in which makes them very easy to test and should make it relatively simple to port this over to the FF extension. I've tried to keep away from using Chrome apis where I can.

Still to do:

* Restore the error states.
* Documentation.
* Possibly remove the `TabStore` all together, the localStorage API has the nice benefit of supporting `[]` accessors, so if we migrate away from using a serialised JSON object to just namespaced keys we can simplify this object dramatically.

I've kind of blitzed through this today after getting fed up with the current background.js so there's likely lots to improve but I'd appreciate feedback. I'm going to continue working on this tomorrow and hopefully we can get at least one of these PR's merged.