stevenyoung/placinglit — pull request #1 by sukima (2014-07-09 03:18:26+00:00)
Title: Refactor allscenes.coffee

By abstracting the parts into functions we can clean up a lot of confusion and repetition.

- Uses jQuery.serializeArray to avoid repetitious and wordy declarations.
- Pulls the ajax code into a micro DSL for easy comprehension.
- DRYs up the endpoint logic
- Uses promises to manage async callback handling. This allows us to place the specifics of the request in a function and not have to worry about how to manage the callback chain.
- illustrates the usefulness of jQuery's chaining syntax.
- Namespaces the events so not to loose click events that might have been placed elsewhere.

This offers a lot more readability and more separation of concerns. It also allow more reuse and places the linkages to the DOM declared up front.

For now this executes on document ready. However, in the future the job of instantiating should be pulled out of this file and handled in a file higher up the module chain. That way this class can be tested in isolation with out inadvertent initialization.

There are two commits. First is a complete refactor of the organization and styled approach to how I would solve the same problem. The second is the same refactor only converted to a class pattern fr the advantage stated above.