Fix the promise hell
This commit is contained in:
parent
cc2ac3dbef
commit
e37aa56def
2 changed files with 15 additions and 24 deletions
|
@ -3,11 +3,10 @@
|
||||||
|
|
||||||
muri.get('bubble')
|
muri.get('bubble')
|
||||||
.story([
|
.story([
|
||||||
[['Beep ...', 'Click, Click, Click ...'], [20, 15]],
|
[['Beep', 'Bip, Bip'], [20, 15]],
|
||||||
[['Urgh ... ....', 'What is wrong with me? ...'], [5, 40]]
|
[['Urgh ... ...', 'Where I am?', 'What happened?'], [35, 40]],
|
||||||
]).then(function() {
|
[['I can\'t see a thing ...', '... need to turn on the light ...'], [35, 40]]
|
||||||
console.log("asdf");
|
]);
|
||||||
})
|
|
||||||
|
|
||||||
act1.update = function() {
|
act1.update = function() {
|
||||||
};
|
};
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
var isactive = false;
|
var isactive = false;
|
||||||
var show = function(text, position) {
|
var show = function(text, position) {
|
||||||
return new Promise(function(resolve) {
|
return new Promise(function(resolve) {
|
||||||
isactive = true;
|
isActive = true;
|
||||||
|
|
||||||
var dom = document.getElementById('bubble');
|
var dom = document.getElementById('bubble');
|
||||||
dom.style.display = '';
|
dom.style.display = '';
|
||||||
|
@ -16,10 +16,10 @@
|
||||||
var show = function() {
|
var show = function() {
|
||||||
if (parts.length === 0) {
|
if (parts.length === 0) {
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
isactive = false;
|
isActive = false;
|
||||||
dom.style.display = 'none';
|
dom.style.display = 'none';
|
||||||
return resolve();
|
return resolve();
|
||||||
}, 4000);
|
}, 2000);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
dom.innerHTML += parts.shift() + ' ';
|
dom.innerHTML += parts.shift() + ' ';
|
||||||
|
@ -30,26 +30,18 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
bubble.talk = function(texts, position) {
|
bubble.talk = function(texts, position) {
|
||||||
return new Promise(function(resolve) {
|
if (texts.length === 0) return;
|
||||||
if (texts.length === 0) {
|
|
||||||
return resolve();
|
|
||||||
}
|
|
||||||
var text = texts.shift();
|
var text = texts.shift();
|
||||||
show(text, position || [5, 40]).then(function() {
|
return show(text, position || [5, 40]).then(function() {
|
||||||
bubble.talk(texts, position);
|
return bubble.talk(texts, position);
|
||||||
});
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
bubble.story = function(talkList) {
|
bubble.story = function(talkList) {
|
||||||
return new Promise(function(resolve, reject) {
|
if (talkList.length === 0) return;
|
||||||
if (talkList.length === 0) {
|
|
||||||
return resolve();
|
|
||||||
}
|
|
||||||
var params = talkList.shift();
|
var params = talkList.shift();
|
||||||
bubble.talk(params[0], params[1]).then(function() {
|
return bubble.talk(params[0], params[1]).then(function() {
|
||||||
bubble.story(talkList);
|
return bubble.story(talkList);
|
||||||
});
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue