React Perf in dev mode // Smarter background component #3240

This commit is contained in:
Nicolas Gotchac 2016-11-21 14:14:25 +01:00
parent 21b2b4ac27
commit ca5fd0b23d
6 changed files with 49 additions and 24 deletions

View File

@ -102,6 +102,7 @@
"postcss-nested": "^1.0.0", "postcss-nested": "^1.0.0",
"postcss-simple-vars": "^3.0.0", "postcss-simple-vars": "^3.0.0",
"raw-loader": "^0.5.1", "raw-loader": "^0.5.1",
"react-addons-perf": "~15.3.2",
"react-addons-test-utils": "~15.3.2", "react-addons-test-utils": "~15.3.2",
"react-copy-to-clipboard": "^4.2.3", "react-copy-to-clipboard": "^4.2.3",
"react-dom": "~15.3.2", "react-dom": "~15.3.2",

View File

@ -46,6 +46,12 @@ import './index.html';
injectTapEventPlugin(); injectTapEventPlugin();
if (process.env.NODE_ENV === 'development') {
// Expose the React Performance Tools on the`window` object
const Perf = require('react-addons-perf');
window.Perf = Perf;
}
const AUTH_HASH = '#/auth?'; const AUTH_HASH = '#/auth?';
const parityUrl = process.env.PARITY_URL || const parityUrl = process.env.PARITY_URL ||
( (

View File

@ -16,26 +16,17 @@
import React, { Component, PropTypes } from 'react'; import React, { Component, PropTypes } from 'react';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
class ParityBackground extends Component { class ParityBackground extends Component {
static contextTypes = {
muiTheme: PropTypes.object.isRequired
}
static propTypes = { static propTypes = {
style: PropTypes.object.isRequired,
children: PropTypes.node, children: PropTypes.node,
className: PropTypes.string, className: PropTypes.string,
gradient: PropTypes.string,
seed: PropTypes.any,
settings: PropTypes.object.isRequired,
onClick: PropTypes.func onClick: PropTypes.func
} };
render () { render () {
const { muiTheme } = this.context; const { children, className, style, onClick } = this.props;
const { children, className, gradient, seed, settings, onClick } = this.props;
const style = muiTheme.parity.getBackgroundStyle(gradient, seed || settings.backgroundSeed);
return ( return (
<div <div
@ -48,17 +39,29 @@ class ParityBackground extends Component {
} }
} }
function mapStateToProps (state) { function mapStateToProps (_, initProps) {
const { settings } = state; const { gradient, seed, muiTheme } = initProps;
return { settings }; let _seed = seed;
let _props = { style: muiTheme.parity.getBackgroundStyle(gradient, seed) };
return (state, props) => {
const { backgroundSeed } = state.settings;
const { seed } = props;
const newSeed = seed || backgroundSeed;
if (newSeed === _seed) {
return _props;
} }
function mapDispatchToProps (dispatch) { _seed = newSeed;
return bindActionCreators({}, dispatch); _props = { style: muiTheme.parity.getBackgroundStyle(gradient, newSeed) };
return _props;
};
} }
export default connect( export default connect(
mapStateToProps, mapStateToProps
mapDispatchToProps
)(ParityBackground); )(ParityBackground);

View File

@ -22,6 +22,10 @@ import { Errors, ParityBackground, Tooltips } from '../../../ui';
import styles from '../application.css'; import styles from '../application.css';
export default class Container extends Component { export default class Container extends Component {
static contextTypes = {
muiTheme: PropTypes.object.isRequired
};
static propTypes = { static propTypes = {
children: PropTypes.node.isRequired, children: PropTypes.node.isRequired,
showFirstRun: PropTypes.bool, showFirstRun: PropTypes.bool,
@ -30,9 +34,10 @@ export default class Container extends Component {
render () { render () {
const { children, showFirstRun, onCloseFirstRun } = this.props; const { children, showFirstRun, onCloseFirstRun } = this.props;
const { muiTheme } = this.context;
return ( return (
<ParityBackground className={ styles.container }> <ParityBackground className={ styles.container } muiTheme={ muiTheme }>
<FirstRun <FirstRun
visible={ showFirstRun } visible={ showFirstRun }
onClose={ onCloseFirstRun } /> onClose={ onCloseFirstRun } />

View File

@ -28,6 +28,10 @@ import imagesEthcoreBlock from '../../../assets/images/parity-logo-white-no-text
import styles from './parityBar.css'; import styles from './parityBar.css';
class ParityBar extends Component { class ParityBar extends Component {
static contextTypes = {
muiTheme: PropTypes.object.isRequired
};
static propTypes = { static propTypes = {
pending: PropTypes.array, pending: PropTypes.array,
dapp: PropTypes.bool dapp: PropTypes.bool
@ -62,6 +66,7 @@ class ParityBar extends Component {
renderBar () { renderBar () {
const { dapp } = this.props; const { dapp } = this.props;
const { muiTheme } = this.context;
if (!dapp) { if (!dapp) {
return null; return null;
@ -75,7 +80,7 @@ class ParityBar extends Component {
return ( return (
<div className={ styles.bar }> <div className={ styles.bar }>
<ParityBackground className={ styles.corner }> <ParityBackground className={ styles.corner } muiTheme={ muiTheme }>
<div className={ styles.cornercolor }> <div className={ styles.cornercolor }>
<Link to='/apps'> <Link to='/apps'>
<Button <Button
@ -95,9 +100,11 @@ class ParityBar extends Component {
} }
renderExpanded () { renderExpanded () {
const { muiTheme } = this.context;
return ( return (
<div className={ styles.overlay }> <div className={ styles.overlay }>
<ParityBackground className={ styles.expanded }> <ParityBackground className={ styles.expanded } muiTheme={ muiTheme }>
<div className={ styles.header }> <div className={ styles.header }>
<div className={ styles.title }> <div className={ styles.title }>
<ContainerTitle title='Parity Signer: Pending' /> <ContainerTitle title='Parity Signer: Pending' />

View File

@ -81,6 +81,7 @@ class Background extends Component {
renderBackgrounds () { renderBackgrounds () {
const { settings } = this.props; const { settings } = this.props;
const { seeds } = this.state; const { seeds } = this.state;
const { muiTheme } = this.context;
return seeds.map((seed, index) => { return seeds.map((seed, index) => {
return ( return (
@ -89,7 +90,9 @@ class Background extends Component {
<ParityBackground <ParityBackground
className={ settings.backgroundSeed === seed ? styles.seedactive : styles.seed } className={ settings.backgroundSeed === seed ? styles.seedactive : styles.seed }
seed={ seed } seed={ seed }
onClick={ this.onSelect(seed) } /> onClick={ this.onSelect(seed) }
muiTheme={ muiTheme }
/>
</div> </div>
</div> </div>
); );