-
-
Notifications
You must be signed in to change notification settings - Fork 631
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an integration test for registerRenderer
Added a new page /client_side_manual_render. This page renders the react component `ManualRenderApp`, which is registered on the client side using `registerRenderer`. The given renderer function just renders some simple html to the DOM. The integration test tests for the presence of the html rendered by the ManualRenderApp renderer. The test passing suggests that ReactOnRails properly delegates to the renderer function on client startup.
- Loading branch information
1 parent
99955f9
commit 9b98494
Showing
6 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
spec/dummy/app/views/pages/client_side_manual_render.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<%= render "header" %> | ||
|
||
<%= react_component("ManualRenderApp", props: {}, prerender: false) %> | ||
<hr/> | ||
|
||
<h2>Manual Rendering with registerRenderer</h2> | ||
<ul> | ||
<li> | ||
<p>Use react_component the same way you would if you were using register:</p> | ||
<pre> | ||
<%%= react_component("ManualRenderApp", props: {}, prerender: false) %> | ||
</pre> | ||
<p>spec/dummy/app/views/pages/client_side_manual_render.html.erb</p> | ||
<br> | ||
</li> | ||
|
||
<li> | ||
<p>Use registerRenderer to expose the rendering function to ReactOnRails:</p> | ||
<pre> | ||
import ManualRenderApp from './ManualRenderAppRenderer'; | ||
|
||
ReactOnRails.registerRenderer({ | ||
ManualRenderApp, | ||
}); | ||
</pre> | ||
<p>spec/dummy/client/app/startup/clientRegistration.jsx</p> | ||
<br> | ||
</li> | ||
|
||
<li> | ||
<p>A renderer is a function that accepts props, railsContext, domNodeId:</p> | ||
<pre> | ||
const ManualRenderApp = (props, railsContext, domNodeId) => { | ||
const reactElement = ( | ||
<%= '<div>' %> | ||
<%= '<h1>Manual Render Example</h1>' %> | ||
<%= '<p>If you can see this, registerRenderer works.</p>' %> | ||
<%= '</div>' %> | ||
); | ||
|
||
ReactDOM.render(reactElement, document.getElementById(domNodeId)); | ||
}; | ||
</pre> | ||
<p>spec/dummy/client/app/startup/ManualRenderAppRenderer.jsx</p> | ||
<br> | ||
</li> | ||
</ul> | ||
|
||
<p> | ||
One possible use case for this is | ||
<a href="https://github.com/shakacode/react_on_rails/blob/master/docs/additional-reading/code-splitting.md"> Code Splitting</a>. | ||
</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
|
||
export default (props, railsContext, domNodeId) => { | ||
const reactElement = ( | ||
<div> | ||
<h1>Manual Render Example</h1> | ||
<p>If you can see this, registerRenderer works.</p> | ||
</div> | ||
); | ||
|
||
ReactDOM.render(reactElement, document.getElementById(domNodeId)); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters