Skip to content

Commit 9237548

Browse files
committed
Switch to named imports
1 parent d09352e commit 9237548

31 files changed

+213
-215
lines changed

docs/api/javascript-api.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Rails has built-in protection for Cross-Site Request Forgery (CSRF), see [Rails Documentation](http://guides.rubyonrails.org/security.html#cross-site-request-forgery-csrf). To nicely utilize this feature in JavaScript requests, React on Rails provides two helpers that can be used as following for POST, PUT or DELETE requests:
66

77
```js
8-
import ReactOnRails from 'react-on-rails';
8+
import * as ReactOnRails from 'react-on-rails';
99

1010
// reads from DOM csrf token generated by Rails in <%= csrf_meta_tags %>
1111
csrfToken = ReactOnRails.authenticityToken();

docs/getting-started.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ issue.
9090
- The `component_name` parameter is a string matching the name you used to expose your React component globally. So, in the above examples, if you had a React component named "HelloWorld", you would register it with the following lines:
9191

9292
```js
93-
import ReactOnRails from 'react-on-rails';
93+
import { register } from 'react-on-rails';
9494
import HelloWorld from './HelloWorld';
95-
ReactOnRails.register({ HelloWorld });
95+
register({ HelloWorld });
9696
```
9797

9898
Exposing your component in this way allows you to reference the component from a Rails view. You can expose as many components as you like, but their names must be unique. See below for the details of how you expose your components via the React on Rails Webpack configuration. You may call `ReactOnRails.register` many times.
@@ -133,8 +133,8 @@ This is how to expose a component to the `react_component` view helper.
133133
```javascript
134134
// app/javascript/packs/hello-world-bundle.js
135135
import HelloWorld from '../components/HelloWorld';
136-
import ReactOnRails from 'react-on-rails';
137-
ReactOnRails.register({ HelloWorld });
136+
import { register } from 'react-on-rails';
137+
register({ HelloWorld });
138138
```
139139

140140
#### Different Server-Side Rendering Code (and a Server-Specific Bundle)

docs/guides/file-system-based-automated-bundle-generation.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,15 @@ app/javascript:
103103
└── logo.svg
104104
```
105105
106-
Previously, many applications would use one pack (webpack entrypoint) for many components. In this example, the`application.js` file manually registers server components, `FooComponentOne`, `BarComponentOne` and `BarComponentTwo`.
106+
Previously, many applications would use one pack (webpack entrypoint) for many components. In this example, the `application.js` file manually registers server components, `FooComponentOne`, `BarComponentOne` and `BarComponentTwo`.
107107
108108
```jsx
109-
import ReactOnRails from 'react-on-rails';
109+
import { register } from 'react-on-rails';
110110
import FooComponentOne from '../src/Foo/FooComponentOne';
111111
import BarComponentOne from '../src/Foo/BarComponentOne';
112112
import BarComponentTwo from '../src/Foo/BarComponentTwo';
113113
114-
ReactOnRails.register({ FooComponentOne, BarComponentOne, BarComponentTwo });
114+
register({ FooComponentOne, BarComponentOne, BarComponentTwo });
115115
```
116116

117117
Your layout would contain:

docs/guides/how-to-use-different-files-for-client-and-server-rendering.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ Many projects will have different entry points for client and server rendering.
99
Your Client Entry can look like this:
1010

1111
```js
12-
import ReactOnRails from 'react-on-rails/client';
12+
import { register } from 'react-on-rails/client';
1313
import App from './ClientApp';
14-
ReactOnRails.register({ App });
14+
register({ App });
1515
```
1616

1717
So your Server Entry can look like:
1818

1919
```js
20-
import ReactOnRails from 'react-on-rails';
20+
import { register } from 'react-on-rails';
2121
import App from './ServerApp';
22-
ReactOnRails.register({ App });
22+
register({ App });
2323
```
2424

2525
Note that the only difference is in the imports.

docs/javascript/code-splitting.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Here's an example of how you might use this in practice:
3939
#### clientRegistration.js
4040

4141
```js
42-
import ReactOnRails from 'react-on-rails/client';
42+
import * as ReactOnRails from 'react-on-rails/client';
4343
import NavigationApp from './NavigationApp';
4444

4545
// Note that we're importing a different RouterApp than in serverRegistration.js
@@ -57,7 +57,7 @@ ReactOnRails.register({
5757
#### serverRegistration.js
5858

5959
```js
60-
import ReactOnRails from 'react-on-rails';
60+
import * as ReactOnRails from 'react-on-rails';
6161
import NavigationApp from './NavigationApp';
6262

6363
// Note that we're importing a different RouterApp than in clientRegistration.js
@@ -76,7 +76,7 @@ Note that you should not register a renderer on the server, since there won't be
7676
#### RouterAppRenderer.jsx
7777

7878
```jsx
79-
import ReactOnRails from 'react-on-rails/client';
79+
import * as ReactOnRails from 'react-on-rails/client';
8080
import React from 'react';
8181
import ReactDOM from 'react-dom';
8282
import Router from 'react-router/lib/Router';

docs/javascript/react-router.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ import React from 'react';
4646
import { renderToString } from 'react-dom/server';
4747
import { StaticRouter } from 'react-router';
4848
import { Provider } from 'react-redux';
49-
import ReactOnRails from 'react-on-rails';
49+
import * as ReactOnRails from 'react-on-rails';
5050

5151
// App.jsx from src/client/App.jsx
5252
import App from '../App';
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import ReactOnRails from 'react-on-rails/client';
1+
import { register } from 'react-on-rails/client';
22

33
import <%= config[:component_name] %> from '<%= config[:app_relative_path] %>';
44

55
// This is how react_on_rails can see the HelloWorld in the browser.
6-
ReactOnRails.register({
6+
register({
77
<%= config[:component_name] %>,
88
});
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import ReactOnRails from 'react-on-rails';
1+
import { register } from 'react-on-rails';
22

33
import HelloWorld from '../bundles/HelloWorld/components/HelloWorldServer';
44

55
// This is how react_on_rails can see the HelloWorld in the browser.
6-
ReactOnRails.register({
6+
register({
77
HelloWorld,
88
});

lib/react_on_rails/packs_generator.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def pack_file_contents(file_path)
107107
relative_component_path = relative_component_path_from_generated_pack(file_path)
108108

109109
<<~FILE_CONTENT.strip
110-
import ReactOnRails from 'react-on-rails/client';
110+
import * as ReactOnRails from 'react-on-rails/client';
111111
import #{registered_component_name} from '#{relative_component_path}';
112112
113113
ReactOnRails.register({#{registered_component_name}});
@@ -123,7 +123,7 @@ def create_server_pack
123123

124124
def build_server_pack_content(component_on_server_imports, server_components, client_components)
125125
content = <<~FILE_CONTENT
126-
import ReactOnRails from 'react-on-rails';
126+
import * as ReactOnRails from 'react-on-rails';
127127
128128
#{component_on_server_imports.join("\n")}\n
129129
FILE_CONTENT

0 commit comments

Comments
 (0)