Class: React::Console

Inherits:
Object
  • Object
show all
Defined in:
lib/react/console.rb

Class Method Summary collapse

Class Method Details

.polyfill_jsObject



3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/react/console.rb', line 3

def self.polyfill_js
  # Overwrite global `console` object with something that can capture messages
  # to return to client later for debugging
  <<-JS
  var console = { history: [] };
  ['error', 'log', 'info', 'warn'].forEach(function (fn) {
    console[fn] = function () {
      console.history.push({level: fn, arguments: Array.prototype.slice.call(arguments)});
    };
  });
  JS
end

.replay_as_script_jsObject



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/react/console.rb', line 16

def self.replay_as_script_js
  <<-JS
  (function (history) {
    if (history && history.length > 0) {
      result += '\\n<scr'+'ipt>';
      history.forEach(function (msg) {
        result += '\\nconsole.' + msg.level + '.apply(console, ' + JSON.stringify(msg.arguments) + ');';
      });
      result += '\\n</scr'+'ipt>';
    }
  })(console.history);
  JS
end