-
Notifications
You must be signed in to change notification settings - Fork 79
Before and after package load callbacks #53
Comments
huh? You lost me -- could you provide a small code sample of what you're talking about? |
If I wanted to build a package that keeps track of all of the modules loaded:
This is just a simple example. If events were used, this would be even better, since multiple packages could use the events:
I can see this being useful for people (like myself) that want to put all of their code in ender, but their code is modular, so they can't depend on all modules being there. Instead of a messy try-catch, they can just use a module db to keep track of modules they're interested in. This same idea can be used in development to create a test-suite that performs unit tests on modules in a browser environment. This could help automate testing between browsers. What do you think about it? |
Alright -- sorry for taking so long to get back to you! That makes sense now -- thanks for clearing it up. I think i would prefer this to live outside the ender-js library. In fact -- i feel like this would be a perfect "plugin" for ender (as a separate package). Just wrap the original provide and require methods, and make sure you build the plugin into your ender lib first :) Doing that will give you lots more room to add a proper event system and all that hottness -- stuff we couldn't really get away with adding here. Sound good? I'm going to close this -- but feel free to reopen if you would like to continue to make it's case to be added to the core of the lib. |
Sometimes modules behave differently when other modules are also 'installed', especially for having a premium and free version of a webapp. I have hacked up my own way, but it is just that, a hack. It would be nice to have an API for doing this.
This could be built in ($.packages), or it could be made into a separate module that can be plugged into the API.
Making something as simple as before and after load callbacks would make it easy to make something like this, and also could provide the ability to make some pretty cool package-management modules (loading bars, lazy-loading of modules, etc).
Perhaps attaching it to
provide
could do the trick:There would have to be a way to ensure that the module that is attaching callbacks to the provide method is executed first. I can't think of a clean way without requiring the module to have a specific 'keyword' in it's package.json.
It might, alternatively, be nice to have an event module. Provide could emit an event that could be listened to. This would have the same requirement as the other way, unless ender delays emitting events until all modules have been loaded. This seems a little messy to me, but I guess it could work.
I don't know the best way to do this, or even if the current setup can easily support this.
The text was updated successfully, but these errors were encountered: