Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
R
renderjs
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Klaus Wölfel
renderjs
Commits
91266b6c
Commit
91266b6c
authored
Jan 21, 2014
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ensure that gadget dependencies are loaded in the right order.
Thanks to Thibaut Frain for this patch.
parent
03fbd623
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
11 deletions
+68
-11
renderjs.js
renderjs.js
+11
-4
test/renderjs_test.js
test/renderjs_test.js
+57
-7
No files found.
renderjs.js
View file @
91266b6c
...
@@ -107,6 +107,13 @@
...
@@ -107,6 +107,13 @@
if
(
options
.
element
===
undefined
)
{
if
(
options
.
element
===
undefined
)
{
options
.
element
=
document
.
createElement
(
"
div
"
);
options
.
element
=
document
.
createElement
(
"
div
"
);
}
}
function
loadDependency
(
method
,
url
)
{
return
function
()
{
return
method
(
url
);
};
}
return
new
RSVP
.
Queue
()
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
.
push
(
function
()
{
return
renderJS
.
declareGadgetKlass
(
url
);
return
renderJS
.
declareGadgetKlass
(
url
);
...
@@ -131,17 +138,17 @@
...
@@ -131,17 +138,17 @@
})
})
// Load all JS/CSS
// Load all JS/CSS
.
push
(
function
(
all_list
)
{
.
push
(
function
(
all_list
)
{
var
parameter_list
=
[]
,
var
q
=
new
RSVP
.
Queue
()
,
i
;
i
;
// Load JS
// Load JS
for
(
i
=
0
;
i
<
all_list
[
0
].
length
;
i
+=
1
)
{
for
(
i
=
0
;
i
<
all_list
[
0
].
length
;
i
+=
1
)
{
parameter_list
.
push
(
renderJS
.
declareJS
(
all_list
[
0
][
i
]));
q
.
push
(
loadDependency
(
renderJS
.
declareJS
,
all_list
[
0
][
i
]));
}
}
// Load CSS
// Load CSS
for
(
i
=
0
;
i
<
all_list
[
1
].
length
;
i
+=
1
)
{
for
(
i
=
0
;
i
<
all_list
[
1
].
length
;
i
+=
1
)
{
parameter_list
.
push
(
renderJS
.
declareCSS
(
all_list
[
1
][
i
]));
q
.
push
(
loadDependency
(
renderJS
.
declareCSS
,
all_list
[
1
][
i
]));
}
}
return
RSVP
.
all
(
parameter_list
)
;
return
q
;
})
})
.
push
(
function
()
{
.
push
(
function
()
{
return
gadget_instance
;
return
gadget_instance
;
...
...
test/renderjs_test.js
View file @
91266b6c
...
@@ -1540,13 +1540,63 @@
...
@@ -1540,13 +1540,63 @@
});
});
});
});
// test('load dependency in the right order', function () {
test
(
'
load dependency in the right order
'
,
function
()
{
// // Check that JS dependencies are loaded in the right order
// Check that JS dependencies are loaded in the right order
// // Can be reproduce with real loading (http):
var
gadget
=
new
RenderJSGadget
(),
// // * enormous 1 js
html_url
=
'
https://example.org/files/qunittest/test22.html
'
,
// // * second small js which require the 1 one to be loaded
js1_url
=
"
data:application/javascript;base64,
"
+
// // How to mock the loading time?
window
.
btoa
(
// });
"
test_js1 = {};
"
),
js2_url
=
"
data:application/javascript;base64,
"
+
window
.
btoa
(
"
test_js1.test_js2 = {}
"
),
js3_url
=
"
data:application/javascript;base64,
"
+
window
.
btoa
(
"
test_js1.test_js2.test_js3 = {}
"
),
js4_url
=
"
data:application/javascript;base64,
"
+
window
.
btoa
(
"
test_js1.test_js2.test_js3.test_js4 = {}
"
),
js5_url
=
"
data:application/javascript;base64,
"
+
window
.
btoa
(
"
test_js1.test_js2.test_js3.test_js4.test_js5 = {}
"
),
js6_url
=
"
data:application/javascript;base64,
"
+
window
.
btoa
(
"
test_js1.test_js2.test_js3.test_js4.test_js5.test_js6 = 'foo'
"
),
html
=
"
<html>
"
+
"
<head>
"
+
"
<title>Foo title</title>
"
+
"
<script src='
"
+
js1_url
+
"
' type='text/javascript'></script>
"
+
"
<script src='
"
+
js2_url
+
"
' type='text/javascript'></script>
"
+
"
<script src='
"
+
js3_url
+
"
' type='text/javascript'></script>
"
+
"
<script src='
"
+
js4_url
+
"
' type='text/javascript'></script>
"
+
"
<script src='
"
+
js5_url
+
"
' type='text/javascript'></script>
"
+
"
<script src='
"
+
js6_url
+
"
' type='text/javascript'></script>
"
+
"
</head><body><p>Bar content</p></body></html>
"
;
this
.
server
.
respondWith
(
"
GET
"
,
html_url
,
[
200
,
{
"
Content-Type
"
:
"
text/html
"
},
html
]);
stop
();
gadget
.
declareGadget
(
html_url
)
.
then
(
function
(
new_gadget
)
{
equal
(
window
.
test_js1
.
test_js2
.
test_js3
.
test_js4
.
test_js5
.
test_js6
,
'
foo
'
);
})
.
fail
(
function
(
e
)
{
ok
(
false
);
})
.
always
(
function
()
{
start
();
});
});
test
(
'
Fail if klass can not be loaded
'
,
function
()
{
test
(
'
Fail if klass can not be loaded
'
,
function
()
{
// Check that gadget is not created if klass is can not be loaded
// Check that gadget is not created if klass is can not be loaded
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment