Blog

IDEAS AND EXAMPLES ABOUT COMMANGULAR

Version 0.7.0 Is Out.


The last version of commangular is out with some new features. The interception initialization setup has been improved and now is around 14x faster.The implemetation in 0.6.0 was extracting the regexp and then testing all the commands with it. I did some test simulating extra huge applications with 8000 commands and 8000 aspects intercepting 1000 of them, the results were unacceptable, about 14 seconds to initialize commangular.

This is the old code:

for (var i = 0; i < commangular.aspects.length; i++) {

    var aspect = commangular.aspects[i];
    if(/\/(.*)\//.test(aspect.matcher)) {
        for(var key in commangular.commands) {
        var regex = new RegExp(/\/(.*)\//.exec(aspect.matcher)[1]);
        if(regex.test(key)){
            if(!commangular.commands[key].interceptors[aspect.poincut])
            commangular.commands[key].interceptors[aspect.poincut] = [];
        commangular.commands[key].interceptors[aspect.poincut].push(aspect.aspectFunction);
     }
   }  
 }
}

The new implemetation is checking the aspect with a large string with all the command names. I did the same test with same number of commands and aspects and the result was 0.6 secons. It is acceptable now. You can see the new implementation below:

angular.forEach(aspects,function(aspect){

    while((result = aspect.matcher.exec(commandNameString)) != null) {

        if(!commands[result[1]].interceptors[aspect.poincut])
            commands[result[1]].interceptors[aspect.poincut] = [];
        commands[result[1]].interceptors[aspect.poincut]
                .push({func:aspect.aspectFunction,order:aspect.order});
    }
});

Another feature added to 0.7.0 is Event Aspects. Event aspects are the same concept that command aspects, but they intercept all the command group mapped to an event. When you dispatch and event with commangular you can intercept it and execute some function before the command group starts, after or you can intercept any error throwed in all the execution context for that event.You can see how it works in the documentation here.

Some bugs have been fixed on regular expresion matching and some test have been added. In general it is more stable now.

Back
comments powered by Disqus