update some props/state stuff
This commit is contained in:
parent
d5d6f8d7e7
commit
9dd12b7efb
4 changed files with 32 additions and 21 deletions
|
@ -2,7 +2,7 @@ import React from 'react'
|
|||
import { render } from 'react-dom'
|
||||
import { Provider } from 'react-redux'
|
||||
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 store = configureStore(initialState)
|
||||
|
|
|
@ -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);
|
|
@ -12,7 +12,7 @@ class Editor extends React.Component {
|
|||
componentDidMount() {
|
||||
this._cm = CodeMirror(this.refs.container, {
|
||||
theme: 'p5-widget',
|
||||
value: this.props.file.content,
|
||||
value: this.props.content,
|
||||
// value: "var a = 'Hello World!';",
|
||||
lineNumbers: true,
|
||||
mode: 'javascript'
|
||||
|
@ -23,9 +23,9 @@ class Editor extends React.Component {
|
|||
}
|
||||
|
||||
componentDidUpdate(prevProps) {
|
||||
if (this.props.file.content !== prevProps.file.content &&
|
||||
this.props.file.content !== this._cm.getValue()) {
|
||||
this._cm.setValue(this.props.file.content);
|
||||
if (this.props.content !== prevProps.content &&
|
||||
this.props.content !== this._cm.getValue()) {
|
||||
this._cm.setValue(this.props.content);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
27
shared/containers/App/App.jsx
Normal file
27
shared/containers/App/App.jsx
Normal 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);
|
Loading…
Reference in a new issue