Skip to content

Commit

Permalink
chore: bump to 0.6.1
Browse files Browse the repository at this point in the history
  • Loading branch information
ocombe committed Mar 5, 2015
1 parent 3108296 commit 585e354
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 33 deletions.
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
<a name="0.6.1"></a>
# 0.6.1 (2015-03-05)


## Bug Fixes

- karma hack isn't needed anymore
([3108296e](https://github.com/ocombe/ocLazyLoad/commit/3108296e9d78da822e58333f2f7d674531ae937b))
- angular.bootstrap now adds modules to init, not replace them
([bdc03dd9](https://github.com/ocombe/ocLazyLoad/commit/bdc03dd9128eca7fca2421317b9f7b103c9b419c))
- fixed TypeError: Converting circular structure to JSON
([11da36d9](https://github.com/ocombe/ocLazyLoad/commit/11da36d90bc5bae588fa3770430d371d5f935aae))
- don't watch for angular.module calls when you're not lazy loading
([35f7eb5b](https://github.com/ocombe/ocLazyLoad/commit/35f7eb5be57f7753a20d7460c5a380f44e3ac175))


## Performance Improvements

- hash the signature to optimize memory consumption
([1cd9676e](https://github.com/ocombe/ocLazyLoad/commit/1cd9676e8799cff03458f7d2d4d144f624da9cfa))


<a name="0.6.0"></a>
# 0.6.0 (2015-02-27)

Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "oclazyload",
"version": "0.6.0",
"version": "0.6.1",
"description": "Load modules on demand (lazy load) with angularJS",
"main": "dist/ocLazyLoad.min.js",
"homepage": "https://github.com/ocombe/ocLazyLoad",
Expand Down
77 changes: 48 additions & 29 deletions dist/ocLazyLoad.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* oclazyload - Load modules on demand (lazy load) with angularJS
* @version v0.6.0
* @version v0.6.1
* @link https://github.com/ocombe/ocLazyLoad
* @license MIT
* @author Olivier Combe <[email protected]>
Expand All @@ -14,7 +14,8 @@
runBlocks = {},
ocLazyLoad = angular.module('oc.lazyLoad', ['ng']),
broadcast = angular.noop,
modulesToLoad = [];
modulesToLoad = [],
recordDeclarations = [true];

ocLazyLoad.provider('$ocLazyLoad', ['$controllerProvider', '$provide', '$compileProvider', '$filterProvider', '$injector', '$animateProvider',
function($controllerProvider, $provide, $compileProvider, $filterProvider, $injector, $animateProvider) {
Expand Down Expand Up @@ -255,13 +256,15 @@
templatesLoader.ocLazyLoadLoader = true;
}

var filesLoader = function(config, params) {
var filesLoader = function filesLoader(config, params) {
var cssFiles = [],
templatesFiles = [],
jsFiles = [],
promises = [],
cachePromise = null;

recordDeclarations.push(true); // start watching angular.module calls

angular.extend(params || {}, config);

var pushFile = function(path) {
Expand Down Expand Up @@ -356,7 +359,10 @@
return filesLoader(config, params);
});
} else {
return $q.all(promises);
return $q.all(promises).finally(function(res) {
recordDeclarations.pop(); // stop watching angular.module calls
return res;
});
}
};

Expand Down Expand Up @@ -438,7 +444,6 @@
moduleCache = [],
deferredList = [],
deferred = $q.defer(),
moduleName,
errText;

if(angular.isUndefined(params)) {
Expand Down Expand Up @@ -858,15 +863,15 @@
regInvokes[moduleName][type][invokeName].push(signature);
broadcast('ocLazyLoad.componentLoaded', [moduleName, type, invokeName]);
};
var signature = function(data) {
var signature = function signature(data) {
if(angular.isArray(data)) { // arrays are objects, we need to test for it first
return data.toString();
return hashCode(data.toString());
} else if(angular.isObject(data)) { // constants & values for example
return JSON.stringify(data);
return hashCode(stringify(data));
} else {
if(angular.isDefined(data) && data !== null) {
return data.toString();
} else {
return hashCode(data.toString());
} else { // null & undefined constants
return data;
}
}
Expand Down Expand Up @@ -969,42 +974,56 @@
});

modulesToLoad = []; // reset for next bootstrap
recordDeclarations.pop(); // wait for the next lazy load
}

var bootstrapFct = angular.bootstrap;
angular.bootstrap = function(element, modules, config) {
modulesToLoad = modules.slice(); // make a clean copy
// we use slice to make a clean copy
angular.forEach(modules.slice(), function(module) {
addToLoadList(module);
});
return bootstrapFct(element, modules, config);
};

var addToInit = function addToInit(name) {
if(angular.isString(name) && modulesToLoad.indexOf(name) === -1) {
var addToLoadList = function addToLoadList(name) {
if(recordDeclarations.length > 0 && angular.isString(name) && modulesToLoad.indexOf(name) === -1) {
modulesToLoad.push(name);
}
};

var ngModuleFct = angular.module;
angular.module = function(name, requires, configFn) {
addToInit(name);
addToLoadList(name);
return ngModuleFct(name, requires, configFn);
};

// add unit tests support
if((window.jasmine || window.mocha) && angular.isDefined(angular.mock)) {
var ngMockModuleFct = angular.mock.module;
var windowMockModuleFct = window.module;
window.module = angular.mock.module = function(module) {
var moduleFns = Array.prototype.slice.call(arguments, 0);
if (angular.isObject(module) && !angular.isArray(module)) {
angular.forEach(module, function(value, key) {
addToInit(key);
});
} else if(angular.isString(module)) {
addToInit(module);
}
ngMockModuleFct(module);
var hashCode = function hashCode(str) {
var hash = 0, i, chr, len;
if (str.length == 0) return hash;
for (i = 0, len = str.length; i < len; i++) {
chr = str.charCodeAt(i);
hash = ((hash << 5) - hash) + chr;
hash |= 0; // Convert to 32bit integer
}
}
return hash;
};

var stringify = function stringify(obj) {
var cache = [];
return JSON.stringify(obj, function(key, value) {
if (typeof value === 'object' && value !== null) {
if (cache.indexOf(value) !== -1) {
// Circular reference found, discard key
return;
}
// Store value in our collection
cache.push(value);
}
return value;
});
cache = null; // Enable garbage collection
};

// Array.indexOf polyfill for IE8
if(!Array.prototype.indexOf) {
Expand Down
4 changes: 2 additions & 2 deletions dist/ocLazyLoad.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "oclazyload",
"version": "0.6.0",
"version": "0.6.1",
"description": "Load modules on demand (lazy load) with angularJS",
"main": "dist/ocLazyLoad.min.js",
"author": "Olivier Combe <[email protected]>",
Expand Down

0 comments on commit 585e354

Please sign in to comment.