Skip to content

Commit 5be1cad

Browse files
authored
Upgrade all packages to React v15+ (#213)
* upgrade `frint-react` to React v15. * upgrade `frint-react-server` to React v15. * upgrade `frint-compat` to React v15. * update `frint-react` docs. * update docs for React v15 upgrade. * fix for render tests with latest React v15.6+
1 parent 19f4116 commit 5be1cad

26 files changed

+321
-353
lines changed

package.json

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,5 @@
7474
"sinon": "^2.1.0",
7575
"sinon-chai": "^2.8.0",
7676
"webpack": "^2.2.0"
77-
},
78-
"greenkeeper": {
79-
"ignore": [
80-
"react",
81-
"react-dom"
82-
]
8377
}
8478
}

packages/frint-compat/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@ Via [unpkg](https://unpkg.com) CDN:
4040

4141
```html
4242
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.min.js"></script>
43-
<script src="https://cdnjs.cloudflare.com/ajax/libs/rxjs/5.0.1/Rx.min.js"></script>
44-
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.8/react.min.js"></script>
45-
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.8/react-dom.min.js"></script>
43+
<script src="https://cdnjs.cloudflare.com/ajax/libs/rxjs/5.4.0/Rx.min.js"></script>
44+
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.5.4/react.min.js"></script>
45+
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.5.4/react-dom.min.js"></script>
46+
<script src="https://unpkg.com/[email protected]/prop-types.js"></script>
4647

4748
<script src="https://unpkg.com/frint@latest/dist/frint.min.js"></script>
4849
<script src="https://unpkg.com/frint-model@latest/dist/frint-model.min.js"></script>

packages/frint-compat/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,13 @@
3333
"frint-react": "^1.4.2",
3434
"frint-store": "^1.4.2",
3535
"lodash": "^4.13.1",
36-
"react": "^0.14.8",
37-
"react-dom": "^0.14.8",
3836
"rxjs": "^5.2.0"
3937
},
4038
"devDependencies": {
41-
"frint-test-utils": "^1.3.0"
39+
"frint-test-utils": "^1.3.0",
40+
"prop-types": "^15.5.10",
41+
"react": "^15.5.4",
42+
"react-dom": "^15.5.4"
4243
},
4344
"bugs": {
4445
"url": "https://github.com/Travix-International/frint/issues"
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
import { PropTypes } from 'react';
1+
/* eslint-disable import/no-extraneous-dependencies */
2+
import PropTypes from 'prop-types';
23

34
export default PropTypes;

packages/frint-compat/src/Region.spec.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -262,22 +262,20 @@ describe('frint-compat › components › Region', function () {
262262
it('should not render Region without any available Core App', function () {
263263
resetDOM();
264264

265-
const SampleComponent = React.createClass({
266-
render() {
267-
return (
268-
<div className="sample">
269-
<p className="text">Hello</p>
270-
271-
<Region name="main" />
272-
</div>
273-
);
274-
}
275-
});
265+
function SampleComponent() {
266+
return (
267+
<div className="sample">
268+
<p className="text">Hello</p>
269+
270+
<Region name="main" />
271+
</div>
272+
);
273+
}
276274

277275
ReactDOM.render(<SampleComponent />, document.getElementById('root'));
278276

279277
expect(document.querySelector('#root .sample .text').innerHTML).to.equal('Hello');
280-
expect(document.querySelector('#root .sample').innerHTML).to.contain('Hello</p><noscript');
278+
expect(document.querySelector('#root .sample').innerHTML).to.contain('Hello</p><!-- react-empty:');
281279
});
282280

283281
// NOTE: removed because the method is dropped in v1.x

packages/frint-compat/src/createComponent.js

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
/* eslint-disable import/no-extraneous-dependencies */
12
import React from 'react';
23
import ReactDOM from 'react-dom';
4+
import _ from 'lodash';
35

46
/**
57
* Module that specifies the createComponent function for creating Components.
@@ -21,30 +23,44 @@ export default function createComponent(options = {}) {
2123
throw new Error(`Component ${options.name} missing required method: render`);
2224
}
2325

24-
return React.createClass({
25-
...options,
26+
class GeneratedComponent extends React.Component {
27+
static displayName = options.displayName
28+
? options.displayName
29+
: options.name || 'GeneratedComponent';
30+
31+
constructor(...args) {
32+
super(...args);
33+
34+
_.each(options, (v, k) => {
35+
this[k] = v;
36+
37+
if (typeof this[k] === 'function') {
38+
this[k].bind(this);
39+
}
40+
});
41+
}
2642

2743
componentWillMount() {
2844
if (typeof options.beforeMount === 'function') {
2945
return options.beforeMount.call(this);
3046
}
3147

3248
return null;
33-
},
49+
}
3450

3551
componentDidMount() {
3652
if (typeof options.afterMount === 'function') {
3753
return options.afterMount.call(this);
3854
}
3955

4056
return null;
41-
},
57+
}
4258

4359
componentWillUnmount() {
4460
if (typeof options.beforeUnmount === 'function') {
4561
options.beforeUnmount.call(this);
4662
}
47-
},
63+
}
4864

4965
/**
5066
* Returns the root HTML element of the component.
@@ -55,6 +71,8 @@ export default function createComponent(options = {}) {
5571
*/
5672
getDOMElement() {
5773
return ReactDOM.findDOMNode(this);
58-
},
59-
});
74+
}
75+
}
76+
77+
return GeneratedComponent;
6078
}

packages/frint-compat/src/createComponent.spec.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,11 @@ describe('frint-compat › createComponent', function () {
1818
});
1919

2020
it('returns Component that can be rendered to DOM', function () {
21-
const MyComponent = createComponent({
22-
render() {
23-
return (
24-
<p id="paragraph">Hello World</p>
25-
);
26-
}
27-
});
21+
function MyComponent() {
22+
return (
23+
<p id="paragraph">Hello World</p>
24+
);
25+
}
2826

2927
ReactDOM.render(
3028
<MyComponent />,

packages/frint-compat/src/extendApp.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* global window */
2-
/* eslint-disable no-console */
2+
/* eslint-disable no-console, import/no-extraneous-dependencies */
33
import _ from 'lodash';
44
import React from 'react';
55

packages/frint-compat/src/getMountableComponent.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable import/no-extraneous-dependencies, class-methods-use-this */
12
import React from 'react';
23
import FrintReact from 'frint-react';
34

@@ -9,19 +10,19 @@ export default function makeGetMountableComponent(Frint) {
910

1011
app.beforeMount();
1112

12-
const WrapperComponent = React.createClass({
13+
class WrapperComponent extends React.Component {
1314
componentDidMount() {
1415
app.afterMount();
15-
},
16+
}
1617

1718
componentWillUnmount() {
1819
app.beforeUnmount();
19-
},
20+
}
2021

2122
render() {
2223
return <ComponentInProvider {...this.props} />;
2324
}
24-
});
25+
}
2526

2627
return WrapperComponent;
2728
}

packages/frint-compat/src/h.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable import/no-extraneous-dependencies */
12
import React from 'react';
23

34
export default React.createElement;

0 commit comments

Comments
 (0)