Skip to content

Commit 1fec85a

Browse files
committed
Updates to spec/dummy for new packages
* fixed tests * updated packages in spec/dummy * add prettier
1 parent 11c9014 commit 1fec85a

57 files changed

Lines changed: 2932 additions & 4303 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.eslintrc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
---
2-
extends: eslint-config-shakacode
2+
extends:
3+
- eslint-config-shakacode
4+
- prettier
5+
- prettier/react
36

47
plugins:
5-
- react
8+
- prettier
69

710
globals:
811
__DEBUG_SERVER_ERRORS__: true
@@ -17,7 +20,7 @@ rules:
1720
no-console: 0
1821
function-paren-newline: 0
1922
object-curly-newline: 0
20-
23+
2124

2225
# https://github.com/benmosher/eslint-plugin-import/issues/340
2326
import/no-extraneous-dependencies: 0

CONTRIBUTING.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,6 @@ _Note: running `npm i` automatically builds the npm package before installing. H
127127
### Prereqs
128128
After checking out the repo, making sure you have rvm and nvm setup (setup ruby and node), cd to `spec/dummy` and run `bin/setup` to install ruby dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
129129

130-
Additionally, our RSpec tests use the poltergeist web driver. You will need to install the phantomjs node module:
131-
132-
```sh
133-
yarn global add phantomjs-prebuilt
134-
```
135-
136-
Note this *must* be installed globally for the dummy test project rspec runner to see it properly.
137-
138130
### Local Node Package
139131
Because the example and dummy apps rely on the react-on-rails node package, they should link directly to your local version to pick up any changes you may have made to that package. To achieve this, switch to the dummy app's root directory and run this command below which runs something like [this script](spec/dummy/package.json#L14)
140132

docs/additional-reading/images.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const assetLoaderRules = [
3939

4040

4141

42-
A full example can be found at [spec/dummy/client/app/components/ImageExample/ImageExample.js](../../spec/dummy/client/app/components/ImageExample/ImageExample.js)
42+
A full example can be found at [spec/dummy/client/app/components/ImageExample/ImageExample.jsx](../../spec/dummy/client/app/components/ImageExample/ImageExample.jsx)
4343

4444
You are free to use images either in image tags or as background images in SCSS files. You can
4545
use a "global" location of /client/app/assets/images or a relative path to your JS or SCSS file, as

docs/additional-reading/rails_view_rendering_from_inline_javascript.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ You can easily render React components in your JavaScript with `render` method t
1212
* @param name Name of your registered component
1313
* @param props Props to pass to your component
1414
* @param domNodeId
15+
* @param hydrate [optional] Pass truthy to update server rendered html. Default is falsy
1516
* @returns {virtualDomElement} Reference to your component's backing instance
1617
*/
17-
ReactOnRails.render(componentName, props, elementId)
18+
ReactOnRails.render(componentName, props, domNodeId)
1819
```
1920

2021
## Why do we need this?

docs/api/view-helpers-api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ adding meta-tags to a page. It is exactly like react_component except for the fo
4141

4242
1. `prerender: true` is automatically added to options, as this method doesn't make sense for
4343
client only rendering.
44-
2. Your JavaScript for server rendering must return an Object for the key `server_rendered_html`.
44+
2. Your JavaScript generator function for server rendering must return an Object rather than a React Component.
4545
3. Your view code must expect an object and not a string.
4646

4747
Here is an example of ERB view code:

docs/misc-pending/code-splitting.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Different markup is generated on the client than on the server. Why does this ha
2121

2222
### The solution
2323

24-
To prevent this, you have to wait until the code chunk is fetched before doing the initial render on the client side. To accomplish this, react on rails allows you to register a renderer. This works just like registering a generator function, except that the function you pass takes three arguments: `renderer(props, railsContext, domNodeId)`, and is responsible for calling `ReactDOM.render` to render the component to the DOM. React on rails will automatically detect when a generator function takes three arguments, and will not call `ReactDOM.render`, instead allowing you to control the initial render yourself.
24+
To prevent this, you have to wait until the code chunk is fetched before doing the initial render on the client side. To accomplish this, react on rails allows you to register a renderer. This works just like registering a generator function, except that the function you pass takes three arguments: `renderer(props, railsContext, domNodeId)`, and is responsible for calling `ReactDOM.render` or `ReactDOM.hydrate` to render the component to the DOM. React on rails will automatically detect when a generator function takes three arguments, and will not call `ReactDOM.render` or `ReactDOM.hydrate`, instead allowing you to control the initial render yourself. Note, you have to be careful to call `ReactDOM.hydrate` rather than `ReactDOM.render` if you are are server rendering.
2525

2626
Here's an example of how you might use this in practice:
2727

@@ -115,7 +115,7 @@ See:
115115

116116
- [spec/dummy/client/app/startup/clientRegistration.jsx](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/client/app/startup/clientRegistration.jsx)
117117
- [spec/dummy/client/app/startup/serverRegistration.jsx](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/client/app/startup/serverRegistration.jsx)
118-
- [spec/dummy/client/app/startup/DeferredRenderAppRenderer.jsx](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/client/app/startup/DeferredRenderAppRenderer.jsx) <-- Code splitting implemented here
118+
- [spec/dummy/client/app/startup/DeferredRenderAppClient](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/client/app/startup/DeferredRenderAppClient.jsx)<-- Code splitting implemented here
119119
- [spec/dummy/client/app/startup/DeferredRenderAppServer.jsx](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/client/app/startup/DeferredRenderAppServer.jsx)
120120
- [spec/dummy/client/app/components/DeferredRender.jsx](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/client/app/components/DeferredRender.jsx)
121121
- [spec/dummy/client/app/components/DeferredRenderAsyncPage.jsx](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/client/app/components/DeferredRenderAsyncPage.jsx)

lib/react_on_rails/helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def react_component(component_name, options = {})
136136
# It is exactly like react_component except for the following:
137137
# 1. prerender: true is automatically added, as this method doesn't make sense for client only
138138
# rendering.
139-
# 2. Your JavaScript for server rendering must return an Object for the key server_rendered_html.
139+
# 2. Your JavaScript generator function for server rendering must return an Object rather than a React component.
140140
# 3. Your view code must expect an object and not a string.
141141
#
142142
# Here is an example of the view code:

node_package/src/ReactOnRails.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,16 @@ ctx.ReactOnRails = {
153153
* @param name Name of your registered component
154154
* @param props Props to pass to your component
155155
* @param domNodeId
156+
* @param hydrate Pass truthy to update server rendered html. Default is falsy
156157
* @returns {virtualDomElement} Reference to your component's backing instance
157158
*/
158-
render(name, props, domNodeId) {
159+
render(name, props, domNodeId, hydrate) {
159160
const componentObj = ComponentRegistry.get(name);
160161
const reactElement = createReactElement({ componentObj, props, domNodeId });
161162

163+
const render = hydrate ? ReactDOM.hydrate : ReactDOM.render;
162164
// eslint-disable-next-line react/no-render-return-value
163-
return ReactDOM.render(reactElement, document.getElementById(domNodeId));
165+
return render(reactElement, document.getElementById(domNodeId));
164166
},
165167

166168
/**

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@
2020
"blue-tape": "^1.0.0",
2121
"create-react-class": "^15.6.0",
2222
"eslint": "^5.7.0",
23+
"eslint-config-prettier": "^3.1.0",
2324
"eslint-config-shakacode": "^16.0.1",
2425
"eslint-plugin-import": "^2.6.1",
2526
"eslint-plugin-jsx-a11y": "^6.1.2",
27+
"eslint-plugin-prettier": "^3.0.0",
2628
"eslint-plugin-react": "^7.1.0",
2729
"flow-bin": "^0.83.0",
2830
"jsdom": "^11.1.0",
@@ -85,6 +87,9 @@
8587
},
8688
"homepage": "https://github.com/shakacode/react_on_rails#readme",
8789
"dependencies": {
88-
"@babel/runtime-corejs2": "^7.0.0"
90+
"@babel/runtime-corejs2": "^7.0.0",
91+
"nps": "^5.9.3",
92+
"prettier": "^1.14.3",
93+
"prettier-eslint-cli": "^4.7.1"
8994
}
9095
}

spec/dummy/.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

0 commit comments

Comments
 (0)