Skip to content

Commit 0f21ff6

Browse files
committed
Merge pull request #72 from gonzaloruizdevilla/master
fix(callback): callback was called twice when lib was already loaded
2 parents d24a765 + d768822 commit 0f21ff6

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

src/script.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@
5151
path = !force && path.indexOf('.js') === -1 && !/^https?:\/\//.test(path) && scriptpath ? scriptpath + path + '.js' : path
5252
if (scripts[path]) {
5353
if (id) ids[id] = 1
54-
if (scripts[path] == 2) callback()
55-
else return setTimeout(function () { loading(path, true) }, 0)
54+
return (scripts[path] == 2) ? callback() : setTimeout(function () { loading(path, true) }, 0)
5655
}
5756

5857
scripts[path] = 1

tests/tests.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,14 @@ script('../node_modules/domready/ready.js', function () {
133133
script('double-load', load)
134134
})
135135

136+
test('correctly count loaded scripts', function (done){
137+
script.path('../vendor/')
138+
script(['patha', 'pathb', 'http://ded.github.com/morpheus/morpheus.js', 'http://ajax.googleapis.com/ajax/libs/angularjs/1.2.19/angular.js'], function () {
139+
ok(typeof angular !== 'undefined', 'loaded angular.js from http')
140+
done();
141+
})
142+
})
143+
136144
})
137145
start()
138146
})

0 commit comments

Comments
 (0)