njx/brackets-livedev2 — pull request #3 by sebaslv (2014-06-04 20:34:14+00:00)
Title: get related documents from browser side

Initial implementation of the mechanism which includes:
- a Document.getRelated operation added to LiveDevProtocol. It retrieves a collection of URLs both for scripts and stylesheets after querying DOM on the browser page and filter those that are external.
- a monitoring mechanism based on MutationObserver interface which sends events for scripts/stylesheets added/removed. MutationEvents are used as fallback for browsers that don't provide support for it.

There are still some work to do and some TODOs in the code. The main opens that I see are:
- [ ] combination of getRelated and monitoring not well defined for the initial sequence
- [ ] start sending monitoring events too early (probably need a queue to collect events until ws is connected)
- [ ] check relationship btw _relatedDocuments at LiveHTMLDocument instance vs. _relatedDocuments at LiveDevelopment. Need to manage context when switching to a different live document in some cases.
- [ ] manage multiple clients (need to take one as a reference assuming DOM is always the same or develop some strategy to manage duplicates and/or potential differences).
- [ ] browser compatibility. I'm new with MutationObserver interface and MutationEvents are being deprecated because of performance issues, need to better understand impact on several versions of desktop/mobile browsers and WebViews.

@njx / @dangoor, please review this initial implementation as an alternative that we came up with @shahab and @busykai after analyzing some of the complexities that a server-side approach would have for building relationships among documents (something that the browser already does for us). This is a key mechanism to start building CSS and JS support on top off so it will probably evolve and be refined to address those cases.