Removed {mangle: false} requirement to uglify-js

Improves solution to #4 for javasript files by 12K (in current build).
This commit is contained in:
Marcin Kurczewski 2014-09-11 12:33:44 +02:00
parent a7d4490b4f
commit 2bb20c49fd
28 changed files with 32 additions and 46 deletions

View file

@ -95,7 +95,6 @@ module.exports = function(grunt) {
uglify: {
dist: {
options: {
mangle: false, //breaks dependency injection
sourceMap: true,
},
files: {

View file

@ -57,4 +57,4 @@ App.API = function(jQuery, promise, appState) {
};
App.DI.registerSingleton('api', App.API);
App.DI.registerSingleton('api', ['jQuery', 'promise', 'appState'], App.API);

View file

@ -158,4 +158,4 @@ App.Auth = function(_, jQuery, util, api, appState, promise) {
};
App.DI.registerSingleton('auth', App.Auth);
App.DI.registerSingleton('auth', ['_', 'jQuery', 'util', 'api', 'appState', 'promise'], App.Auth);

View file

@ -25,7 +25,7 @@ App.Bootstrap = function(auth, router, util, promise) {
};
App.DI.registerSingleton('bootstrap', App.Bootstrap);
App.DI.registerSingleton('bootstrap', ['auth', 'router', 'util', 'promise'], App.Bootstrap);
App.DI.registerManual('jQuery', function() { return window.$; });
App.DI.registerManual('pathJs', function() { return window.Path; });
App.DI.registerManual('_', function() { return window._; });

View file

@ -87,4 +87,4 @@ App.BrowsingSettings = function(
};
App.DI.registerSingleton('browsingSettings', App.BrowsingSettings);
App.DI.registerSingleton('browsingSettings', ['promise', 'auth', 'api'], App.BrowsingSettings);

View file

@ -2,9 +2,6 @@ var App = App || {};
App.DI = (function() {
var STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;
var ARGUMENT_NAMES = /([^\s,]+)/g;
var factories = {};
var instances = {};
@ -17,7 +14,7 @@ App.DI = (function() {
}
var objectInitializer = factory.initializer;
var singleton = factory.singleton;
var deps = resolveDependencies(objectInitializer);
var deps = resolveDependencies(objectInitializer, factory.dependencies);
instance = {};
instance = objectInitializer.apply(instance, deps);
if (singleton) {
@ -27,36 +24,26 @@ App.DI = (function() {
return instance;
}
function resolveDependencies(objectIntializer) {
function resolveDependencies(objectIntializer, depKeys) {
var deps = [];
var depKeys = getFunctionParameterNames(objectIntializer);
for (var i = 0; i < depKeys.length; i ++) {
deps[i] = get(depKeys[i]);
}
return deps;
}
function register(key, objectInitializer) {
factories[key] = {initializer: objectInitializer, singleton: false};
function register(key, dependencies, objectInitializer) {
factories[key] = {initializer: objectInitializer, singleton: false, dependencies: dependencies};
}
function registerSingleton(key, objectInitializer) {
factories[key] = {initializer: objectInitializer, singleton: true};
function registerSingleton(key, dependencies, objectInitializer) {
factories[key] = {initializer: objectInitializer, singleton: true, dependencies: dependencies};
}
function registerManual(key, objectInitializer) {
instances[key] = objectInitializer();
}
function getFunctionParameterNames(func) {
var fnStr = func.toString().replace(STRIP_COMMENTS, '');
var result = fnStr.slice(fnStr.indexOf('(') + 1, fnStr.indexOf(')')).match(ARGUMENT_NAMES);
if (result === null) {
result = [];
}
return result;
}
return {
get: get,
register: register,

View file

@ -23,4 +23,4 @@ App.Presenters.CommentListPresenter = function(
};
App.DI.register('commentListPresenter', App.Presenters.CommentListPresenter);
App.DI.register('commentListPresenter', ['jQuery', 'topNavigationPresenter'], App.Presenters.CommentListPresenter);

View file

@ -23,4 +23,4 @@ App.Presenters.HelpPresenter = function(
};
App.DI.register('helpPresenter', App.Presenters.HelpPresenter);
App.DI.register('helpPresenter', ['jQuery', 'topNavigationPresenter'], App.Presenters.HelpPresenter);

View file

@ -23,4 +23,4 @@ App.Presenters.HomePresenter = function(
};
App.DI.register('homePresenter', App.Presenters.HomePresenter);
App.DI.register('homePresenter', ['jQuery', 'topNavigationPresenter'], App.Presenters.HomePresenter);

View file

@ -77,4 +77,4 @@ App.Presenters.LoginPresenter = function(
};
App.DI.register('loginPresenter', App.Presenters.LoginPresenter);
App.DI.register('loginPresenter', ['_', 'jQuery', 'util', 'promise', 'router', 'auth', 'topNavigationPresenter', 'messagePresenter'], App.Presenters.LoginPresenter);

View file

@ -33,4 +33,4 @@ App.Presenters.LogoutPresenter = function(
};
App.DI.register('logoutPresenter', App.Presenters.LogoutPresenter);
App.DI.register('logoutPresenter', ['jQuery', 'promise', 'router', 'auth', 'topNavigationPresenter', 'messagePresenter'], App.Presenters.LogoutPresenter);

View file

@ -38,4 +38,4 @@ App.Presenters.MessagePresenter = function(jQuery) {
};
App.DI.register('messagePresenter', App.Presenters.MessagePresenter);
App.DI.register('messagePresenter', ['jQuery'], App.Presenters.MessagePresenter);

View file

@ -116,4 +116,4 @@ App.Presenters.PagedCollectionPresenter = function(_, util, promise, api) {
};
App.DI.register('pagedCollectionPresenter', App.Presenters.PagedCollectionPresenter);
App.DI.register('pagedCollectionPresenter', ['_', 'util', 'promise', 'api'], App.Presenters.PagedCollectionPresenter);

View file

@ -23,4 +23,4 @@ App.Presenters.PostListPresenter = function(
};
App.DI.register('postListPresenter', App.Presenters.PostListPresenter);
App.DI.register('postListPresenter', ['jQuery', 'topNavigationPresenter'], App.Presenters.PostListPresenter);

View file

@ -23,4 +23,4 @@ App.Presenters.PostUploadPresenter = function(
};
App.DI.register('postUploadPresenter', App.Presenters.PostUploadPresenter);
App.DI.register('postUploadPresenter', ['jQuery', 'topNavigationPresenter'], App.Presenters.PostUploadPresenter);

View file

@ -94,4 +94,4 @@ App.Presenters.RegistrationPresenter = function(
};
App.DI.register('registrationPresenter', App.Presenters.RegistrationPresenter);
App.DI.register('registrationPresenter', ['_', 'jQuery', 'util', 'promise', 'api', 'topNavigationPresenter', 'messagePresenter'], App.Presenters.RegistrationPresenter);

View file

@ -23,4 +23,4 @@ App.Presenters.TagListPresenter = function(
};
App.DI.register('tagListPresenter', App.Presenters.TagListPresenter);
App.DI.register('tagListPresenter', ['jQuery', 'topNavigationPresenter'], App.Presenters.TagListPresenter);

View file

@ -52,4 +52,4 @@ App.Presenters.TopNavigationPresenter = function(
};
App.DI.registerSingleton('topNavigationPresenter', App.Presenters.TopNavigationPresenter);
App.DI.registerSingleton('topNavigationPresenter', ['_', 'jQuery', 'util', 'promise', 'auth'], App.Presenters.TopNavigationPresenter);

View file

@ -78,4 +78,4 @@ App.Presenters.UserAccountRemovalPresenter = function(
};
App.DI.register('userAccountRemovalPresenter', App.Presenters.UserAccountRemovalPresenter);
App.DI.register('userAccountRemovalPresenter', ['_', 'jQuery', 'util', 'promise', 'api', 'auth', 'router', 'messagePresenter'], App.Presenters.UserAccountRemovalPresenter);

View file

@ -166,4 +166,4 @@ App.Presenters.UserAccountSettingsPresenter = function(
};
App.DI.register('userAccountSettingsPresenter', App.Presenters.UserAccountSettingsPresenter);
App.DI.register('userAccountSettingsPresenter', ['_', 'jQuery', 'util', 'promise', 'api', 'auth', 'messagePresenter'], App.Presenters.UserAccountSettingsPresenter);

View file

@ -109,4 +109,4 @@ App.Presenters.UserActivationPresenter = function(
};
App.DI.register('userActivationPresenter', App.Presenters.UserActivationPresenter);
App.DI.register('userActivationPresenter', ['_', 'jQuery', 'promise', 'util', 'auth', 'api', 'router', 'topNavigationPresenter', 'messagePresenter'], App.Presenters.UserActivationPresenter);

View file

@ -67,4 +67,4 @@ App.Presenters.UserBrowsingSettingsPresenter = function(
};
App.DI.register('userBrowsingSettingsPresenter', App.Presenters.UserBrowsingSettingsPresenter);
App.DI.register('userBrowsingSettingsPresenter', ['_', 'jQuery', 'util', 'promise', 'auth', 'browsingSettings', 'messagePresenter'], App.Presenters.UserBrowsingSettingsPresenter);

View file

@ -73,4 +73,4 @@ App.Presenters.UserListPresenter = function(
};
App.DI.register('userListPresenter', App.Presenters.UserListPresenter);
App.DI.register('userListPresenter', ['_', 'jQuery', 'util', 'promise', 'auth', 'router', 'pagedCollectionPresenter', 'topNavigationPresenter', 'messagePresenter'], App.Presenters.UserListPresenter);

View file

@ -87,4 +87,4 @@ App.Presenters.UserPresenter = function(
};
App.DI.register('userPresenter', App.Presenters.UserPresenter);
App.DI.register('userPresenter', ['_', 'jQuery', 'util', 'promise', 'api', 'auth', 'topNavigationPresenter', 'userBrowsingSettingsPresenter', 'userAccountSettingsPresenter', 'userAccountRemovalPresenter', 'messagePresenter'], App.Presenters.UserPresenter);

View file

@ -25,4 +25,4 @@ App.Promise = function(jQuery) {
};
App.DI.registerSingleton('promise', App.Promise);
App.DI.registerSingleton('promise', ['jQuery'], App.Promise);

View file

@ -59,4 +59,4 @@ App.Router = function(pathJs, _, jQuery, util, appState) {
};
App.DI.registerSingleton('router', App.Router);
App.DI.registerSingleton('router', ['pathJs', '_', 'jQuery', 'util', 'appState'], App.Router);

View file

@ -49,4 +49,4 @@ App.State = function() {
};
App.DI.registerSingleton('appState', App.State);
App.DI.registerSingleton('appState', [], App.State);

View file

@ -160,4 +160,4 @@ App.Util = function(_, jQuery, promise) {
};
App.DI.registerSingleton('util', App.Util);
App.DI.registerSingleton('util', ['_', 'jQuery', 'promise'], App.Util);