dart-lang/spark — pull request #1677 by ussuri (2014-04-23 08:04:50+00:00)
Title: Break the circular dependency between the app and the UI to stabilize startup

@devoncarew

* Removed SparkModel.instance to avoid clients mistakenly deciding they can use the singleton at any time. SparkModel is still a singleton by nature, ensured by an assert().
* Split Spark ctor into a bare minimum ctor + init(), the latter to be called only once the UI is guaranteed to have loaded.
* Added SparkPolymerUI.modelReady() to initialize the model in the UI after the model has started.
* Reshuffled startup sequence to implement the following sequence using the above:
1) The UI loads.
2) The model (the app) starts up, looking up necessary HTML elements in the ready UI.
3) UI is notified that the model has started, in order to initialize it for later use in the event handlers, and to refresh the UI (e.g. based on developerMode).