Skip to content

Commit ac14b4f

Browse files
committed
Fixed the broken each function.
The return value of `setTimeout` in `return (scripts[path] == 2) ? callback() : setTimeout(function () { loading(path, true) }, 0)` will stop the `each` function (implemented by `every`) When loading different files lists that sharing the same file, the one called later will never been loaded (see the test).
1 parent 419f5c4 commit ac14b4f

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/script.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
}
2424
function each(ar, fn) {
2525
every(ar, function (el) {
26-
return !fn(el)
26+
fn(el)
27+
return 1
2728
})
2829
}
2930

tests/tests.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,15 @@ script('../node_modules/domready/ready.js', function () {
141141
})
142142
})
143143

144+
test('double loaded file in different loading list', 2, function() {
145+
script(['../vendor/lab2.js', '../vendor/lab2.min.js'], function() {
146+
ok(true, 'lab2 and lab2.min have been loaded')
147+
})
148+
script(['../vendor/lab2.js', '../vendor/head.js'], function() {
149+
ok(true, 'lab2 and head have been loaded')
150+
})
151+
})
152+
144153
})
145154
start()
146155
})

0 commit comments

Comments
 (0)