update some props/state stuff

This commit is contained in:
catarak 2016-05-05 19:01:31 -04:00
parent d5d6f8d7e7
commit 9dd12b7efb
4 changed files with 32 additions and 21 deletions

View file

@ -2,7 +2,7 @@ import React from 'react'
import { render } from 'react-dom' import { render } from 'react-dom'
import { Provider } from 'react-redux' import { Provider } from 'react-redux'
import configureStore from '../shared/redux/store/configureStore' import configureStore from '../shared/redux/store/configureStore'
import App from '../shared/components/App/App' import App from '../shared/containers/App/App'
const initialState = window.__INITIAL_STATE__ const initialState = window.__INITIAL_STATE__
const store = configureStore(initialState) const store = configureStore(initialState)

View file

@ -1,16 +0,0 @@
import Editor from '../Editor/Editor'
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'
import * as FileActions from '../../redux/actions'
function mapStateToProps(state) {
return {
file: state.file
}
}
function mapDispatchToProps(dispatch) {
return bindActionCreators(FileActions, dispatch);
}
export default connect(mapStateToProps, mapDispatchToProps)(Editor);

View file

@ -12,7 +12,7 @@ class Editor extends React.Component {
componentDidMount() { componentDidMount() {
this._cm = CodeMirror(this.refs.container, { this._cm = CodeMirror(this.refs.container, {
theme: 'p5-widget', theme: 'p5-widget',
value: this.props.file.content, value: this.props.content,
// value: "var a = 'Hello World!';", // value: "var a = 'Hello World!';",
lineNumbers: true, lineNumbers: true,
mode: 'javascript' mode: 'javascript'
@ -23,9 +23,9 @@ class Editor extends React.Component {
} }
componentDidUpdate(prevProps) { componentDidUpdate(prevProps) {
if (this.props.file.content !== prevProps.file.content && if (this.props.content !== prevProps.content &&
this.props.file.content !== this._cm.getValue()) { this.props.content !== this._cm.getValue()) {
this._cm.setValue(this.props.file.content); this._cm.setValue(this.props.content);
} }
} }

View file

@ -0,0 +1,27 @@
import React from 'react';
import Editor from '../../components/Editor/Editor'
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'
import * as FileActions from '../../redux/actions'
class App extends React.Component {
render() {
return (
<Editor
content={this.props.file.content}
updateFile={this.props.updateFile}/>
);
}
}
function mapStateToProps(state) {
return {
file: state.file
}
}
function mapDispatchToProps(dispatch) {
return bindActionCreators(FileActions, dispatch);
}
export default connect(mapStateToProps, mapDispatchToProps)(App);