Git Product home page Git Product logo

modulus's People

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

modulus's Issues

Optionally write out runtime config

for shim config, it is convenient to write out the config for runtime.

var modulusConfig = {
    shim:{...}
};

modulus should check for a runtime config when init is called, and merge that config in with any other configs.

Fix for IE8 global functions option

IE8 does not support the global functions option, e.g.

function moduleA(moduleB){

}

because global variables are not enumerable.
e.g.

function moduleA(){}

for(var key in window){
    console.log(key); //would not print 'moduleA' in IE8
}

We could potentially fixing this by adding a config option:

 /**
         * When set to true, will attempt to fix ie8 issue with global vars not being enumerable, by registering modules
         * as they are requested by first checking if there is
         */
        globalModuleFunctionsMode: false,

And attempt to register modules as they are requested, instead of registering them all at once.

Force use of context

if context is not supplied via the config, do not scan the window for potential functions.

shim config should still be called though:

_findAndRegisterModules:function (){
            var foundModuleFunctions = this._findModuleFunctions();
            var foundModules = this._createModulesFromFunctions(foundModuleFunctions);
            if(this.shim){
                var shimModules = this._createModulesFromShim();
                foundModules = shimModules.concat(foundModules);//foundModules.concat(shimModules);
            }
            this._registerModules(foundModules);
        }

Excludes Configuration

Allow excluding certain modules (and module's dependencies) in the build dist configuration.

dist:{
                files:{
                    './dist/testProject/pageOne.js':{
                        dependencies:['pageOne'], 
                        excludes:['someModule'] 
                    }
                }
            },

Build config option for other files

Provide a build option to include any other js files.
Should be at the file level.

modulus.build({
    dist:{
         files:{
             './dist/someFile.js': {
                 include:[
                     {
                        path: './src/vendor/metrics.js',
                        locationInDistFile: 'bottom' //place at the bottom of built file
                      }
                 ]
             }
         }
    }
});

IOC map config

allow for inversion of control by providing a map configuration.

map:{
        requestsFor:{
            'moduleA':{
                from:{
                    'moduleB':{

                    }
                }
            }
        },
        requestsFrom:{
            'moduleB':{
                for:{
                    'moduleA':{
                        shouldGetThisModule:{
                            'moduleB':{
                                //any configuration overrides
                            }
                        },
                        //or
                        executeThisFirst: function(moduleA){

                        }
                        //...
                    }
                }
            }
        }
    },

Third Party Library Shim - Runtime Config

Third party libraries which don't use modulus formatting for module definitions need to have a shim configuration.
e.g.

modulus.init({
     shim:{
          '$': {
               dependencies: [],
               export: '$'
           }
     }
});

See Shim Build Config: #2

AMD Support

Allow for modules to be asynchronously downloaded at runtime.

function moduleA(asynchModuleB){
}
moduleA.module = {
    params:{
        asynchModuleB: 'http://www.example.com/js/moduleB.js'
    }
}

or

modulus.config({
    paths:{
        'asynchModuleB':'http://www.example.com/js/moduleB.js'
    }
});

Provide register and start

Allow module registration to happen without initializing any modules.

Ensure that once a module is registered, it can't be re-registered (to help prevent issues with globally defined functions)

Provide define function for optional way of registering modules

Alternatively, require and define could be the same function:
require when no function name give, define when function name given.

modulus(function(moduleA){

});
modulus(function moduleB(){

}, {metadata});

//shortcut
m(function moduleA(){

})({
   autoInit:true
});

or just the old commonjs-similar way

modulus.define(function moduleA(moduleB){
    return {
       prop1: 123 + moduleB.prop1
    }
}, {autoInit:true}); //metadata is second param

modulus.define(function moduleB(){
    return {
        prop1: 1
    };
});

Third Party Library Shim - Build Config

Third party libraries which don't use modulus formatting for module definitions need to have a shim configuration.
e.g.

modulus.build({
     shim:{
          '$': {
               path:'src/vendor/jquery.js',
               dependencies: [],
               export: '$'
           }
     }
});

Protect against minification

Minification will rename param names, remove function names if the named function is passed into another function, etc. and this messes with modulus.

Provide an api similar to requirejs which the build engine can use during build.
e.g. modulus.build({protectAgainstMinification:true})

m('moduleName', ['dependencyName1', 'dependencyName2'], function(dep1, dep2){...}, {metadata});

Support Contexts other than Window

Some may feel that global module functions are too risky, and opt to use a namespace instead.

Need to finish implementing _findModuleFunction (pass it the configured context)
Also _createModuleFromFunction needs to figure out the function name based on a syntax like:

var myContext = {};
myContext.moduleA = function (moduleB){};

Ensure all metadata is added

When a module is registered, make sure that all its metadata is included.

e.g. _createModuleFromFunction should return object with all metadata.

Circular Dependency Detection

lib/modulus.js _recursivelyFindDependencies needs detection for circular dependencies.

What I would like is logic to detect that there is a circular dependency, and break out of recursion when it's detected.

e.g. moduleA depends on moduleB which depends on moduleC which depends on moduleA.

I haven't run into an issue with circular deps before, but I think it's a valid issue. http://stackoverflow.com/questions/4881059/how-to-handle-circular-dependencies-with-requirejs-amd

Async Shim - No callback issue

in the async-loading-spec, i found an issue when implementing fakeWindow for another ie8 bug (cant delete window properties)

if backbone and underscore aren't assigned to fakeWindow, the require for Backbone is never resolved.

it may be an exception that is getting swallowed...
investigate further

Support on ('event')

Support modulus.on('event', function(){...})

especially to allow custom handling of modules as they are registered

modulus.on('registerModule', function(moduleMetadata){
    if(moduleMetadata.isWidget){ ...}
});

Runtime detection of duplicate module definitions

if a module is defined twice during runtime, there can be issues, so provide detection.

var context = {};
context.moduleA = function(moduleB){}
context.moduleA = function(){}

we can probably facilitate this with getter setters or observers.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Working_with_Objects#Defining_getters_and_setters

modulus.init({
    _defineContextSetter:function(){
         //by default use native. if devs want to polyfill, they can override this function.
    }
});

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.