I have three functions: show(), hide(), and swap() that control the current template displayed in the layout, given the id of the template container element.
I'd like the swap function to call show and when show returns a value, I'd like to trigger the hide function.
E.g.
var hide = function(template) {
TweenMax.to(frame, 1.18, {
opacity: 0,
onComplete: function() {
return true;
}
});
}
var show = function(template) {
}
var swap = function(currentTemplate, targetTemplate) {
// hide(currentTemplate) then when "true" is returned, show(targetTemplate)
}
swap();
The onComplete function inside TweenMax runs after 1.18 seconds. I know I could put show() inside this or pass show into the hide function, but I'd rather keep the two independent if possible.
Is there a way to do this (preferably w/o jQuery)?
Thanks!!
as long as hide and show are synchronous -- which since they both are simple DOM updates, seems likely to be true -- you can use
swap
for control flow.That said, if these actions were asynchronous (if they required AJAX requests, for instance) this approach would not work. You would have to pass around callbacks to get them working, or use the new Promise in es6 interface to get things working.