Skip to content

Commit d81260c

Browse files
committed
Use getDefaultProps instead of setting porps
1 parent 76c014b commit d81260c

2 files changed

Lines changed: 43 additions & 25 deletions

File tree

‎skins/base/views/organisms/ErrorDialog.js‎

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ limitations under the License.
1717
'use strict';
1818

1919
/*
20-
* Usage:
20+
* Usage:
2121
* Modal.createDialog(ErrorDialog, {
2222
* title: "some text", (default: "Error")
2323
* description: "some more text",
@@ -28,31 +28,11 @@ limitations under the License.
2828
*/
2929

3030
var React = require('react');
31+
var ErrorDialogController = require("../../../../src/controllers/organisms/ErrorDialog");
3132

3233
module.exports = React.createClass({
3334
displayName: 'ErrorDialog',
34-
35-
// can't use getDefaultProps, see Modal.js
36-
componentWillMount: function() {
37-
if (!this.props.title) {
38-
this.props.title = "Error";
39-
}
40-
if (!this.props.description) {
41-
this.props.description = "An error has occurred.";
42-
}
43-
if (!this.props.button) {
44-
this.props.button = "OK";
45-
}
46-
if (this.props.focus === undefined) {
47-
this.props.focus = true;
48-
}
49-
if (!this.props.onClose) {
50-
var self = this;
51-
this.props.onClose = function() {
52-
self.props.onFinished();
53-
};
54-
}
55-
},
35+
mixins: [ErrorDialogController],
5636

5737
render: function() {
5838
return (
@@ -61,11 +41,10 @@ module.exports = React.createClass({
6141
{this.props.title}
6242
</div>
6343
{this.props.description}<br />
64-
<button onClick={this.props.onClose} autoFocus={this.props.focus}>
44+
<button onClick={this.props.onFinished} autoFocus={this.props.focus}>
6545
{this.props.button}
6646
</button>
6747
</div>
6848
);
6949
}
7050
});
71-
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
Copyright 2015 OpenMarket Ltd
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
'use strict';
18+
19+
var React = require("react");
20+
21+
module.exports = {
22+
propTypes: {
23+
title: React.PropTypes.string,
24+
description: React.PropTypes.string,
25+
button: React.PropTypes.string,
26+
focus: React.PropTypes.bool,
27+
onFinished: React.PropTypes.func.isRequired,
28+
},
29+
30+
getDefaultProps: function() {
31+
var self = this;
32+
return {
33+
title: "Error",
34+
description: "An error has occurred.",
35+
button: "OK",
36+
focus: true,
37+
};
38+
},
39+
};

0 commit comments

Comments
 (0)