-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
vinogradov
committed
Aug 8, 2017
1 parent
076f873
commit 3c1e474
Showing
5 changed files
with
193 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
|
||
class Component extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
console.log('constructor'); // eslint-disable-line no-console | ||
this.state = {value: 1}; | ||
|
||
this.onClickHandler = this.onClickHandler.bind(this); | ||
} | ||
|
||
componentWillMount() { | ||
console.log('componentWillMount'); // eslint-disable-line no-console | ||
} | ||
|
||
componentDidMount() { | ||
console.log('componentDidMount'); // eslint-disable-line no-console | ||
} | ||
|
||
componentWillReceiveProps() { | ||
console.log('componentWillReceiveProps'); // eslint-disable-line no-console | ||
} | ||
|
||
shouldComponentUpdate() { | ||
console.log('shouldComponentUpdate'); // eslint-disable-line no-console | ||
return true; | ||
} | ||
|
||
componentWillUpdate() { | ||
console.log('componentWillUpdate'); // eslint-disable-line no-console | ||
} | ||
|
||
componentDidUpdate() { | ||
console.log('componentDidUpdate'); // eslint-disable-line no-console | ||
} | ||
|
||
onClickHandler() { | ||
this.setState({value: 1}); | ||
} | ||
|
||
render() { | ||
console.log('render', this.props); // eslint-disable-line no-console | ||
|
||
return <button onClick={this.onClickHandler}>setState</button>; | ||
} | ||
} | ||
|
||
ReactDOM.render( | ||
<Component />, | ||
document.querySelector('#app') | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import {Component} from './component'; | ||
|
||
class ParentComponent extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = {value: 1}; | ||
|
||
this.onClickHandler = this.onClickHandler.bind(this); | ||
} | ||
|
||
onClickHandler() { | ||
this.setState({value: 1}); | ||
} | ||
|
||
render() { | ||
return ( | ||
<div> | ||
<button onClick={this.onClickHandler}>setState</button> | ||
<Component value={this.state.value} /> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
ReactDOM.render( | ||
<ParentComponent />, | ||
document.querySelector('#app') | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import * as React from 'react'; | ||
import * as ReactDOM from 'react-dom'; | ||
import {Provider, connect} from 'react-redux'; | ||
import {createStore, applyMiddleware, combineReducers} from 'redux'; | ||
import logger from 'redux-logger'; | ||
import {Component} from './component'; | ||
|
||
const VALUE_1_INCREMENT = 'VALUE_1_INCREMENT'; | ||
function value1Increment() { | ||
return { | ||
type: VALUE_1_INCREMENT | ||
}; | ||
} | ||
|
||
const VALUE_2_INCREMENT = 'VALUE_2_INCREMENT'; | ||
function value2Increment() { | ||
return { | ||
type: VALUE_2_INCREMENT | ||
}; | ||
} | ||
|
||
function reducer(state = {value1: {deepProp: 0}, value2: 0}, action) { | ||
switch (action.type) { | ||
case VALUE_1_INCREMENT: | ||
return { | ||
...state, | ||
value1: {deepProp: state.value1.deepProp + 1} | ||
}; | ||
case VALUE_2_INCREMENT: | ||
return { | ||
...state, | ||
value2: state.value2 + 1 | ||
}; | ||
default: | ||
return state; | ||
} | ||
} | ||
|
||
const ConnectedComponent = connect(state => ({ | ||
value: state.reducer.value1 | ||
}))(Component); | ||
|
||
const store = createStore( | ||
combineReducers({reducer}), | ||
applyMiddleware(logger) | ||
); | ||
|
||
window.value1Increment = () => { | ||
store.dispatch(value1Increment()); | ||
}; | ||
|
||
window.value2Increment = () => { | ||
store.dispatch(value2Increment()); | ||
}; | ||
|
||
|
||
ReactDOM.render( | ||
<Provider store={store}> | ||
<ConnectedComponent /> | ||
</Provider>, | ||
document.querySelector('#app') | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
export class Component extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
console.log('constructor'); // eslint-disable-line no-console | ||
} | ||
|
||
componentWillMount() { | ||
console.log('componentWillMount'); // eslint-disable-line no-console | ||
} | ||
|
||
componentDidMount() { | ||
console.log('componentDidMount'); // eslint-disable-line no-console | ||
} | ||
|
||
componentWillReceiveProps() { | ||
console.log('componentWillReceiveProps'); // eslint-disable-line no-console | ||
} | ||
|
||
shouldComponentUpdate() { | ||
console.log('shouldComponentUpdate'); // eslint-disable-line no-console | ||
return true; | ||
} | ||
|
||
componentWillUpdate() { | ||
console.log('componentWillUpdate'); // eslint-disable-line no-console | ||
} | ||
|
||
componentDidUpdate() { | ||
console.log('componentDidUpdate'); // eslint-disable-line no-console | ||
} | ||
|
||
render() { | ||
console.log('render', this.props); // eslint-disable-line no-console | ||
|
||
return <span>{JSON.stringify(this.props.value)}</span>; | ||
// return null; | ||
} | ||
} | ||
|
||
Component.propTypes = { | ||
value: PropTypes.shape({}).isRequired | ||
}; |