Skip to content

Commit a75dac3

Browse files
author
Robert Mosolgo
committed
Merge pull request #455 from danott/polyfill-cleanup
Use .js files for CONSOLE_POLYFILL and CONSOLE_REPLAY
2 parents 3d3b0e5 + 6f801ec commit a75dac3

File tree

3 files changed

+19
-23
lines changed

3 files changed

+19
-23
lines changed

lib/react/server_rendering/sprockets_renderer.rb

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
module React
66
module ServerRendering
77
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+
812
def initialize(options={})
913
@replay_console = options.fetch(:replay_console, true)
1014
filenames = options.fetch(:files, ["react-server.js", "components.js"])
@@ -35,29 +39,6 @@ def render(component_name, props, prerender_options)
3539
def after_render(component_name, props, prerender_options)
3640
@replay_console ? CONSOLE_REPLAY : ""
3741
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
6142
end
6243
end
6344
end
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
var console = { history: [] };
2+
['error', 'log', 'info', 'warn'].forEach(function (fn) {
3+
console[fn] = function () {
4+
console.history.push({level: fn, arguments: Array.prototype.slice.call(arguments)});
5+
};
6+
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
(function (history) {
2+
if (history && history.length > 0) {
3+
result += '\\n<scr'+'ipt>';
4+
history.forEach(function (msg) {
5+
result += '\\nconsole.' + msg.level + '.apply(console, ' + JSON.stringify(msg.arguments) + ');';
6+
});
7+
result += '\\n</scr'+'ipt>';
8+
}
9+
})(console.history);

0 commit comments

Comments
 (0)