Skip to content

Commit

Permalink
load sync (update to 0.0.4)
Browse files Browse the repository at this point in the history
  • Loading branch information
raphamorim committed Sep 28, 2016
1 parent e78037b commit 5068884
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 13 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ loads as non-blocking too, however Nautilus.js doesn't care if it's an anonymous
<script>
nautilus.config({
paths: {
'jquery': 'libs/jquery',
'jquery.nanoscroller': 'libs/jquery-nanoscroller',
'jquery': 'libs/jquery.js',
'jquery.nanoscroller': 'libs/jquery-nanoscroller.js',
'waterfall': 'http://cdnjs.cloudflare.com/ajax/libs/waterfall.js/1.0.2/waterfall.min.js'
}
});
Expand Down Expand Up @@ -86,7 +86,7 @@ To define specified paths, you must use the config method:
```js
nautilus.config({
paths: {
'jquery': 'libs/jquery',
'jquery': 'libs/jquery.js',
'waterfall': 'http://cdnjs.cloudflare.com/ajax/libs/waterfall.js/1.0.2/waterfall.min.js'
}
});
Expand Down
12 changes: 8 additions & 4 deletions nautilus.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ var queue = {
function loadScript(path, currentQueue) {
var scr = document.createElement('script');

scr.type = "text/javascript";
scr.type = 'text/javascript';
scr.onload = handleLoad;
scr.async = true;
scr.onreadystatechange = handleReadyStateChange;
Expand All @@ -70,7 +70,7 @@ function loadScript(path, currentQueue) {
}

function handleReadyStateChange() {
if (scr.readyState === "complete") {
if (scr.readyState === 'complete') {
handleLoad();
}
}
Expand All @@ -83,12 +83,16 @@ function loadScript(path, currentQueue) {
}
}

function fetch(paths, fn) {
function fetch(paths, depsOrFn, fn) {
if (typeof(paths) === 'string') {
paths = [paths];
}

var q = queue.push(paths.length, fn);
if (Object.prototype.toString.call(depsOrFn) === '[object Array]') {
depsOrFn = fetch.bind(this, depsOrFn, fn);
}

var q = queue.push(paths.length, depsOrFn);
for (var i = 0; i < paths.length; i++) {
var path = paths[i];
loadScript(uPaths[path] || path, q);
Expand Down
2 changes: 1 addition & 1 deletion nautilus.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nautilusjs",
"version": "0.0.2",
"version": "0.0.4",
"description": "Async JavaScript loader & dependency manager",
"main": "nautilus.js",
"scripts": {
Expand Down
12 changes: 8 additions & 4 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
function loadScript(path, currentQueue) {
var scr = document.createElement('script');

scr.type = "text/javascript";
scr.type = 'text/javascript';
scr.onload = handleLoad;
scr.async = true;
scr.onreadystatechange = handleReadyStateChange;
Expand All @@ -14,7 +14,7 @@ function loadScript(path, currentQueue) {
}

function handleReadyStateChange() {
if (scr.readyState === "complete") {
if (scr.readyState === 'complete') {
handleLoad();
}
}
Expand All @@ -27,12 +27,16 @@ function loadScript(path, currentQueue) {
}
}

function fetch(paths, fn) {
function fetch(paths, depsOrFn, fn) {
if (typeof(paths) === 'string') {
paths = [paths];
}

var q = queue.push(paths.length, fn);
if (Object.prototype.toString.call(depsOrFn) === '[object Array]') {
depsOrFn = fetch.bind(this, depsOrFn, fn);
}

var q = queue.push(paths.length, depsOrFn);
for (var i = 0; i < paths.length; i++) {
var path = paths[i];
loadScript(uPaths[path] || path, q);
Expand Down
14 changes: 14 additions & 0 deletions test/test-fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,18 @@ describe('Fetch', function() {
});
});
});
describe('synchronous queue load', function() {
context('testing one synchronous request in order', function() {
it('should execute callback on success and the scripts on head end', function(done) {
window.dep0 = undefined;
window.dep1 = undefined;
expect(window.dep0).to.be.equal(undefined);
nautilus(['fixtures/dep0.js'], ['fixtures/subdep0.js'], function() {
expect(window.dep0).to.be.equal("dep0");
expect(window.subdep0).to.be.equal("dep0");
done();
});
});
});
});
});

0 comments on commit 5068884

Please sign in to comment.