Skip to content

Commit 0bad5fa

Browse files
committed
Switch to named imports
1 parent 20e4455 commit 0bad5fa

33 files changed

+215
-216
lines changed

docs/api/javascript-api.md

Lines changed: 1 addition & 1 deletion
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,15 @@ app/javascript:
115115
└── logo.svg
116116
```
117117
118-
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`.
118+
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`.
119119
120120
```jsx
121-
import ReactOnRails from 'react-on-rails';
121+
import { register } from 'react-on-rails';
122122
import FooComponentOne from '../src/Foo/FooComponentOne';
123123
import BarComponentOne from '../src/Foo/BarComponentOne';
124124
import BarComponentTwo from '../src/Foo/BarComponentTwo';
125125
126-
ReactOnRails.register({ FooComponentOne, BarComponentOne, BarComponentTwo });
126+
register({ FooComponentOne, BarComponentOne, BarComponentTwo });
127127
```
128128

129129
Your layout would contain:

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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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';
Lines changed: 2 additions & 2 deletions
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
});
Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def pack_file_contents(file_path)
111111
relative_component_path = relative_component_path_from_generated_pack(file_path)
112112

113113
<<~FILE_CONTENT.strip
114-
import ReactOnRails from 'react-on-rails/client';
114+
import * as ReactOnRails from 'react-on-rails/client';
115115
import #{registered_component_name} from '#{relative_component_path}';
116116
117117
ReactOnRails.register({#{registered_component_name}});
@@ -127,7 +127,7 @@ def create_server_pack
127127

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

0 commit comments

Comments
 (0)