Giter VIP home page Giter VIP logo

Comments (3)

fat avatar fat commented on August 18, 2024

huh? You lost me -- could you provide a small code sample of what you're talking about?

from ender.

beatgammit avatar beatgammit commented on August 18, 2024

If I wanted to build a package that keeps track of all of the modules loaded:

(function () {
    var modules = [],
        $ = require('ender');

    // called just before the module is loaded
    $.provide.before = function (moduleName) {
        modules.push(moduleName);
    };

    // callback would have the value of the module's module.exports
    $.provide.after = function (module) {
        // or do something smarter, like getting data from modules
        if (init in module) {
            module.init();
        }
    };

    module.exports = modules;
}());

This is just a simple example. If events were used, this would be even better, since multiple packages could use the events:

(function () {
    var modules = [],
        $ = require('ender');

    $.on('provide', function (moduleName, module) {
        // some distinguishing feature
        if (init in module) {
            modules.push(moduleName);
            module.init(moduleName);
        }
    });

    module.exports = modules;
}());

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?

from ender.

fat avatar fat commented on August 18, 2024

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.

from ender.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.