Skip to content

Commit

Permalink
fixed bug where showLog() would only show the last message if multi…
Browse files Browse the repository at this point in the history
…ple messages were printed in succession (#99)
  • Loading branch information
daattali committed Dec 11, 2016
1 parent 14800cb commit e91a1fb
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# shinyjs 0.8.xxxx

- added support for shinyAce editor as the input for `runcodeUI()` (#93)
- fixed bug where `showLog()` would only show the last message if multiple messages were printed in succession (#99)
- fixed bug where date inputs could not be reset to empty (#100)
- fixed textArea inputs not getting disabled when disabling a parent element
- fixed broken `runExample("sandbox")` example
Expand Down
3 changes: 2 additions & 1 deletion R/useShinyjs.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,10 @@ useShinyjs <- function(rmd = FALSE, debug = FALSE, html = FALSE,
initJS,
'(function(){
var oldLog = console.log;
var queue = new ShinySenderQueue();
console.log = function (message) {
try {
Shiny.onInputChange("shinyjs-showLog", message);
queue.send("shinyjs-showLog", message);
} catch(err) {}
oldLog.apply(console, arguments);
};
Expand Down
31 changes: 31 additions & 0 deletions inst/srcjs/shinyjs-default-funcs.js
Original file line number Diff line number Diff line change
Expand Up @@ -788,3 +788,34 @@ shinyjs = function() {

// Initialize shinyjs on the JS side
$(function() { shinyjs.initShinyjs(); });

// ShinySenderQueue code taken from Joe Cheng
// https://github.com/rstudio/shiny/issues/1476
function ShinySenderQueue() {
this.readyToSend = true;
this.queue = [];
this.timer = null;
}
ShinySenderQueue.prototype.send = function(name, value) {
var self = this;
function go() {
self.timer = null;
if (self.queue.length) {
var msg = self.queue.shift();
Shiny.onInputChange(msg.name, msg.value);
self.timer = setTimeout(go, 0);
} else {
self.readyToSend = true;
}
}
if (this.readyToSend) {
this.readyToSend = false;
Shiny.onInputChange(name, value);
this.timer = setTimeout(go, 0);
} else {
this.queue.push({name: name, value: value});
if (!this.timer) {
this.timer = setTimeout(go, 0);
}
}
};

0 comments on commit e91a1fb

Please sign in to comment.