Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix a bug #1

Merged
merged 1 commit into from

2 participants

@mbarzeev

where the callback was invoked for as many times as the files count and not just once when all are loaded

@stuartmemo stuartmemo merged commit 8ac4c1f into stuartmemo:master
@stuartmemo
Owner

That's great, thanks a lot!

@mbarzeev

Sure mate - keep on the great work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 8, 2012
  1. @mbarzeev

    Fix a bug where the callback was invoked for as many times as the fil…

    mbarzeev authored
    …es count and not just once when all are loaded
This page is out of date. Refresh to see the latest.
Showing with 11 additions and 4 deletions.
  1. +11 −4 abbey-load.js
View
15 abbey-load.js
@@ -22,12 +22,11 @@
request.open('GET', file[fileKey], true);
request.responseType = 'arraybuffer';
- request.onload = function () {
+ request.onload = function () {
filesLoaded++;
context.decodeAudioData(request.response, function (decodedBuffer) {
returnObj[fileKey] = decodedBuffer;
-
- if (filesLoaded === numberOfFiles) {
+ if (Object.size(returnObj) === numberOfFiles) {
callback(returnObj);
}
});
@@ -40,9 +39,9 @@
var returnObj = {};
files.forEach(function (file, index) {
+ numberOfFiles = Object.size(file);
for (var key in file) {
if (file.hasOwnProperty(key)) {
- numberOfFiles++;
loadFile(key, file, returnObj, callback);
}
}
@@ -52,3 +51,11 @@
window.AbbeyLoad = AbbeyLoad;
})(window);
+
+Object.size = function(obj) {
+ var size = 0, key;
+ for (key in obj) {
+ if (obj.hasOwnProperty(key)) size++;
+ }
+ return size;
+};
Something went wrong with that request. Please try again.