Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
renderjs
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
renderjs
Commits
a8eb5043
Commit
a8eb5043
authored
Nov 26, 2018
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Start service after ready
parent
5fc0961f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
4 deletions
+53
-4
renderjs.js
renderjs.js
+7
-4
test/renderjs_test.js
test/renderjs_test.js
+46
-0
No files found.
renderjs.js
View file @
a8eb5043
...
...
@@ -620,8 +620,9 @@
}
function
startService
(
gadget
)
{
if
((
gadget
.
constructor
.
__service_list
.
length
===
0
)
&&
(
!
gadget
.
constructor
.
__job_declared
))
{
if
(((
gadget
.
constructor
.
__service_list
.
length
===
0
)
&&
(
!
gadget
.
constructor
.
__job_declared
))
||
(
gadget
.
hasOwnProperty
(
'
__monitor
'
)))
{
return
;
}
createGadgetMonitor
(
gadget
);
...
...
@@ -906,7 +907,6 @@
gadget_instance
.
element
.
appendChild
(
fragment
);
setAqParent
(
gadget_instance
,
parent_gadget
);
clearGadgetInternalParameters
(
gadget_instance
);
gadget_instance
.
element
.
_gadget
=
gadget_instance
;
if
(
old_element
!==
undefined
)
{
// Add gadget to the DOM if needed
// Do it when all DOM modifications are done
...
...
@@ -999,7 +999,6 @@
gadget_instance
.
state
=
{};
options
.
element
.
appendChild
(
iframe
);
clearGadgetInternalParameters
(
gadget_instance
);
gadget_instance
.
element
.
_gadget
=
gadget_instance
;
// Add gadget to the DOM if needed
// Do it when all DOM modifications are done
old_element
.
parentNode
.
replaceChild
(
options
.
element
,
...
...
@@ -1116,7 +1115,11 @@
// Always set the parent reference when all ready are finished
// in case the gadget declaration is cancelled
// (and ready are not finished)
gadget_instance
.
element
.
_gadget
=
gadget_instance
;
parent_gadget
.
__sub_gadget_dict
[
scope
]
=
gadget_instance
;
if
(
document
.
contains
(
gadget_instance
.
element
))
{
startService
(
gadget_instance
);
}
// Always return the gadget instance after ready function
return
gadget_instance
;
}
...
...
test/renderjs_test.js
View file @
a8eb5043
...
...
@@ -2337,6 +2337,52 @@
});
});
test
(
'
service started after ready is finished
'
,
function
()
{
// couscous romain xxxxxxxxx
// Subclass RenderJSGadget to not pollute its namespace
var
gadget
=
new
RenderJSGadget
(),
html_url
=
'
https://example.org/files/qunittest/test5011.html
'
,
defer
=
RSVP
.
defer
();
gadget
.
__sub_gadget_dict
=
{};
this
.
server
.
respondWith
(
"
GET
"
,
html_url
,
[
200
,
{
"
Content-Type
"
:
"
text/html
"
},
"
<html><body></body></html>
"
]);
document
.
getElementById
(
'
qunit-fixture
'
).
innerHTML
=
"
<div></div>
"
;
stop
();
expect
(
1
);
renderJS
.
declareGadgetKlass
(
html_url
)
.
then
(
function
(
Klass
)
{
Klass
.
declareService
(
function
()
{
defer
.
reject
(
'
Triggered before ready
'
);
});
Klass
.
ready
(
function
()
{
return
RSVP
.
delay
(
500
)
.
then
(
function
()
{
defer
.
resolve
(
'
Triggered before service
'
);
});
});
return
gadget
.
declareGadget
(
html_url
,
{
element
:
document
.
getElementById
(
'
qunit-fixture
'
)
.
querySelector
(
"
div
"
)}
);
})
.
then
(
function
()
{
return
defer
.
promise
;
})
.
then
(
function
(
result
)
{
equal
(
result
,
'
Triggered before service
'
);
})
.
fail
(
function
(
e
)
{
ok
(
false
,
e
);
})
.
always
(
function
()
{
start
();
});
});
test
(
'
service started when gadget element added in DOM
'
,
function
()
{
// Subclass RenderJSGadget to not pollute its namespace
var
service1
=
{},
...
...
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