|
5 | 5 | module React
|
6 | 6 | module ServerRendering
|
7 | 7 | class SprocketsRenderer < ExecJSRenderer
|
| 8 | + # Reimplement console methods for replaying on the client |
| 9 | + CONSOLE_POLYFILL = File.read(File.join(File.dirname(__FILE__), "sprockets_renderer/console_polyfill.js")) |
| 10 | + CONSOLE_REPLAY = File.read(File.join(File.dirname(__FILE__), "sprockets_renderer/console_replay.js")) |
| 11 | + |
8 | 12 | def initialize(options={})
|
9 | 13 | @replay_console = options.fetch(:replay_console, true)
|
10 | 14 | filenames = options.fetch(:files, ["react-server.js", "components.js"])
|
@@ -35,29 +39,6 @@ def render(component_name, props, prerender_options)
|
35 | 39 | def after_render(component_name, props, prerender_options)
|
36 | 40 | @replay_console ? CONSOLE_REPLAY : ""
|
37 | 41 | end
|
38 |
| - |
39 |
| - # Reimplement console methods for replaying on the client |
40 |
| - CONSOLE_POLYFILL = <<-JS |
41 |
| - var console = { history: [] }; |
42 |
| - ['error', 'log', 'info', 'warn'].forEach(function (fn) { |
43 |
| - console[fn] = function () { |
44 |
| - console.history.push({level: fn, arguments: Array.prototype.slice.call(arguments)}); |
45 |
| - }; |
46 |
| - }); |
47 |
| - JS |
48 |
| - |
49 |
| - # Replay message from console history |
50 |
| - CONSOLE_REPLAY = <<-JS |
51 |
| - (function (history) { |
52 |
| - if (history && history.length > 0) { |
53 |
| - result += '\\n<scr'+'ipt>'; |
54 |
| - history.forEach(function (msg) { |
55 |
| - result += '\\nconsole.' + msg.level + '.apply(console, ' + JSON.stringify(msg.arguments) + ');'; |
56 |
| - }); |
57 |
| - result += '\\n</scr'+'ipt>'; |
58 |
| - } |
59 |
| - })(console.history); |
60 |
| - JS |
61 | 42 | end
|
62 | 43 | end
|
63 | 44 | end
|
0 commit comments