Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Es2015 classes #1734

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
11 changes: 10 additions & 1 deletion docs/src/app/app.jsx
Expand Up @@ -3,7 +3,16 @@
let React = require('react'),
Router = require('react-router'),
AppRoutes = require('./app-routes.jsx'),
injectTapEventPlugin = require("react-tap-event-plugin");
injectTapEventPlugin = require("react-tap-event-plugin"),
shallowEqual = require('react/lib/shallowEqual');

// Remove after upgrading to React 0.14.
React.addons.shallowCompare = function(instance, nextProps, nextState) {
return (
!shallowEqual(instance.props, nextProps) ||
!shallowEqual(instance.state, nextState)
);
}

//Needed for React Developer Tools
window.React = React;
Expand Down
49 changes: 25 additions & 24 deletions docs/src/app/components/code-example/code-block.jsx
Expand Up @@ -3,33 +3,25 @@ const { Styles } = require('material-ui');
const { Spacing } = Styles;


const CodeBlock = React.createClass({
class CodeBlock extends React.Component {
constructor(props, context) {
super(props, context);

contextTypes : {
muiTheme: React.PropTypes.object
},

//for passing default theme context to children
childContextTypes: {
muiTheme: React.PropTypes.object,
},

getChildContext () {
return {
muiTheme: this.state.muiTheme,
this.state = {
muiTheme: this.context.muiTheme ? this.context.muiTheme : ThemeManager.getMuiTheme(DefaultRawTheme),
};
},
}

getInitialState () {
getChildContext() {
return {
muiTheme: this.context.muiTheme ? this.context.muiTheme : ThemeManager.getMuiTheme(DefaultRawTheme),
muiTheme: this.state.muiTheme,
};
},
}

componentWillReceiveProps (nextProps, nextContext) {
componentWillReceiveProps(nextProps, nextContext) {
let newMuiTheme = nextContext.muiTheme ? nextContext.muiTheme : this.state.muiTheme;
this.setState({muiTheme: newMuiTheme});
},
}

componentDidMount() {
var code = React.findDOMNode(this.refs.code);
Expand All @@ -42,17 +34,26 @@ const CodeBlock = React.createClass({
readOnly: true,
});
});
},
}

shouldComponentUpdate({children}, nextState){
shouldComponentUpdate({children}, nextState) {
return this.props.children !== children;
},
}

render() {
return (
<textarea ref="code" value={this.props.children} readOnly={true}/>
);
},
});
}
}

//for passing default theme context to children
CodeBlock.childContextTypes = {
muiTheme: React.PropTypes.object,
};

CodeBlock.contextTypes = {
muiTheme: React.PropTypes.object
};

module.exports = CodeBlock;
53 changes: 27 additions & 26 deletions docs/src/app/components/code-example/code-example.jsx
Expand Up @@ -15,38 +15,25 @@ const CodeBlock = require('./code-block');
const ThemeManager = Styles.ThemeManager;
const DefaultRawTheme = Styles.LightRawTheme;

const CodeExample = React.createClass({
class CodeExample extends React.Component {
constructor(props, context) {
super(props, context);

propTypes : {
code: React.PropTypes.string.isRequired,
layoutSideBySide: React.PropTypes.bool,
},

contextTypes : {
muiTheme: React.PropTypes.object
},

//for passing default theme context to children
childContextTypes: {
muiTheme: React.PropTypes.object,
},

getChildContext () {
return {
muiTheme: this.state.muiTheme,
this.state = {
muiTheme: this.context.muiTheme ? this.context.muiTheme : ThemeManager.getMuiTheme(DefaultRawTheme),
};
},
}

getInitialState () {
getChildContext() {
return {
muiTheme: this.context.muiTheme ? this.context.muiTheme : ThemeManager.getMuiTheme(DefaultRawTheme),
muiTheme: this.state.muiTheme,
};
},
}

componentWillReceiveProps (nextProps, nextContext) {
componentWillReceiveProps(nextProps, nextContext) {
let newMuiTheme = nextContext.muiTheme ? nextContext.muiTheme : this.state.muiTheme;
this.setState({muiTheme: newMuiTheme});
},
}

render() {

Expand Down Expand Up @@ -91,7 +78,21 @@ const CodeExample = React.createClass({
<CodeBlock style={styles.codeBlock}>{code}</CodeBlock>
</Paper>
);
},
});
}
}

//for passing default theme context to children
CodeExample.childContextTypes = {
muiTheme: React.PropTypes.object,
};

CodeExample.contextTypes = {
muiTheme: React.PropTypes.object
};

CodeExample.propTypes = {
code: React.PropTypes.string.isRequired,
layoutSideBySide: React.PropTypes.bool,
};

module.exports = CodeExample;