{"action":"closed","issue":{"url":"https://api.github.com/repos/whatwg/loader/issues/18","labels_url":"https://api.github.com/repos/whatwg/loader/issues/18/labels{/name}","comments_url":"https://api.github.com/repos/whatwg/loader/issues/18/comments","events_url":"https://api.github.com/repos/whatwg/loader/issues/18/events","html_url":"https://github.com/whatwg/loader/issues/18","id":57851531,"number":18,"title":"Loader Hooks and State","user":{"login":"EisenbergEffect","id":131485,"avatar_url":"https://avatars.githubusercontent.com/u/131485?v=3","gravatar_id":"","url":"https://api.github.com/users/EisenbergEffect","html_url":"https://github.com/EisenbergEffect","followers_url":"https://api.github.com/users/EisenbergEffect/followers","following_url":"https://api.github.com/users/EisenbergEffect/following{/other_user}","gists_url":"https://api.github.com/users/EisenbergEffect/gists{/gist_id}","starred_url":"https://api.github.com/users/EisenbergEffect/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/EisenbergEffect/subscriptions","organizations_url":"https://api.github.com/users/EisenbergEffect/orgs","repos_url":"https://api.github.com/users/EisenbergEffect/repos","events_url":"https://api.github.com/users/EisenbergEffect/events{/privacy}","received_events_url":"https://api.github.com/users/EisenbergEffect/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":25,"created_at":"2015-02-16T21:09:15Z","updated_at":"2015-02-28T03:52:13Z","closed_at":"2015-02-28T03:52:13Z","body":"# Loader Hooks and State\r\n\r\nCurrently, we have the following possible states: \r\n\r\n* fetch\r\n* translate\r\n* instantiate\r\n* link\r\n* ready\r\n\r\nWe also have the following hooks:\r\n\r\n* resolve\r\n* fetch\r\n* translate\r\n* instantiate\r\n\r\nThis is certainly not my area of expertise, but there's a bit of a mismatch here that bothers me. Of particular concern to me is that the entire process of loading a resource is not accessible via hooks. The hooks seem to cut off at the *instantiate* phase, whereas I believe they should follow through to the *ready* phase. There's also a bit of an inconsistency at the beginning, with a missing *resolve* state.\r\n\r\nI believe there was recently some talk around removing the *locate* hook, so it seems there's still issues to be discussed around this topic and I think it's pretty critical that we get this right.\r\n\r\n> **Note:** I realize stuff has only recently been moved over here and there's still lots of work to do. I just wanted to jump in early on an area that's particularly important to me and my community.\r\n\r\nMy personal interest is in having a *ready* hook which would allow me to receive the fully executed module instance along with its metadata. There are a number of important scenarios that this would open up:\r\n\r\n* Insight - Track loads, load times, runtime usage patterns, tracing, etc.\r\n* Instrumentation and AOP - Dynamically instrument or transform code based on the runtime context.\r\n* Metaprogramming - Use metadata defined in instances to generate code on the fly.\r\n* Registries - Application-Specific optimized catalogues of loaded modules for use by frameworks/libraries.\r\n\r\nI'm sure there are other uses as well. One technique I've used repeatedly across multiple module loaders for a number of years now is to tag exports with their module id of origin, thus enabling convention-based programming, ala Rails. It's not possible to do this reliably 100% of the time without a *ready* hook of some sort.\r\n\r\nI've also attempted to proxy *module.execute* but this technique doesn't work for real ES6 modules. So, it's not adequate...not to mention that it seems like a hack. Issue #9 is related to this. @matthewp shows a technique for using *instantiate*. He's got a different scenario, but hits some similar types of inconsistencies.\r\n\r\nSo, I'd love to see additional refinement in this area. And, as I've mentioned, I'm particularly interested in a *ready* hook. I'm also pretty sure I've heard this requested by others in different forums including @jrburke and @guybedford (Though I could be wrong, because it was quite some time ago.)\r\n\r\nLooking forward to working through this and very excited to see the renewed effort on the loader."}}