Skip to content

Commit

Permalink
allow delayed loading
Browse files Browse the repository at this point in the history
  • Loading branch information
moinism committed Jul 16, 2017
1 parent 4c2396e commit 69f668b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
10 changes: 7 additions & 3 deletions build/botui.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@
function _addMessage(_msg) {

if(!_msg.loading && !_msg.content) {
throw Error('BotUI: "content" is required in message object.');
throw Error('BotUI: "content" is required in a non-loading message object.');
}

_msg.type = _msg.type || 'text';
Expand All @@ -185,8 +185,12 @@

return new Promise(function (resolve, reject) {
setTimeout(function () {
if(_msg.delay && !_msg.loading) { // if its a loading message then only do in 'update'
_instance.messages[_index].visible = true;
if(_msg.delay) {
_msg.visible = true;

if(_msg.loading) {
_msg.loading = false;
}
}
resolve(_index);
}, _msg.delay || 0);
Expand Down
2 changes: 1 addition & 1 deletion build/botui.min.js

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

10 changes: 7 additions & 3 deletions src/scripts/botui.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@
function _addMessage(_msg) {

if(!_msg.loading && !_msg.content) {
throw Error('BotUI: "content" is required in message object.');
throw Error('BotUI: "content" is required in a non-loading message object.');
}

_msg.type = _msg.type || 'text';
Expand All @@ -176,8 +176,12 @@

return new Promise(function (resolve, reject) {
setTimeout(function () {
if(_msg.delay && !_msg.loading) { // if its a loading message then only do in 'update'
_instance.messages[_index].visible = true;
if(_msg.delay) {
_msg.visible = true;

if(_msg.loading) {
_msg.loading = false;
}
}
resolve(_index);
}, _msg.delay || 0);
Expand Down
1 change: 1 addition & 0 deletions test.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
}).then(function () {
botui.message.add({
delay: 2000,
loading: true,
content: 'Delayed Hello World'
});
});
Expand Down

0 comments on commit 69f668b

Please sign in to comment.