mirror of
https://github.com/zoriya/react-native-web.git
synced 2026-05-25 23:48:54 +00:00
Reformat 'performance' and 'src' code
This commit is contained in:
@@ -7,14 +7,11 @@ import styles from './styles.css';
|
||||
const Box = ({ color, fixed = false, layout = 'column', outer = false, ...other }) => (
|
||||
<View
|
||||
{...other}
|
||||
className={classnames(
|
||||
styles[`color${color}`],
|
||||
{
|
||||
[styles.fixed]: fixed,
|
||||
[styles.outer]: outer,
|
||||
[styles.row]: layout === 'row'
|
||||
}
|
||||
)}
|
||||
className={classnames(styles[`color${color}`], {
|
||||
[styles.fixed]: fixed,
|
||||
[styles.outer]: outer,
|
||||
[styles.row]: layout === 'row'
|
||||
})}
|
||||
/>
|
||||
);
|
||||
|
||||
|
||||
@@ -3,6 +3,6 @@ import classnames from 'classnames';
|
||||
import React from 'react';
|
||||
import styles from './styles.css';
|
||||
|
||||
const View = (props) => <div {...props} className={classnames(styles.initial, props.className)} />;
|
||||
const View = props => <div {...props} className={classnames(styles.initial, props.className)} />;
|
||||
|
||||
module.exports = View;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import { css } from 'glamor';
|
||||
import React from 'react';
|
||||
|
||||
const View = (props) => <div {...props} className={css(viewStyle, props.style)} />;
|
||||
const View = props => <div {...props} className={css(viewStyle, props.style)} />;
|
||||
|
||||
const viewStyle = {
|
||||
alignItems: 'stretch',
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import createDOMElement from 'react-native/modules/createDOMElement';
|
||||
import StyleSheet from 'react-native/apis/StyleSheet';
|
||||
|
||||
const View = (props) => createDOMElement('div', { ...props, style: [ styles.initial, props.style ] });
|
||||
const View = props => createDOMElement('div', { ...props, style: [styles.initial, props.style] });
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
initial: {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import styled from 'styled-components';
|
||||
import View from '../View';
|
||||
|
||||
const getColor = (color) => {
|
||||
const getColor = color => {
|
||||
switch (color) {
|
||||
case 0:
|
||||
return '#222';
|
||||
@@ -21,11 +21,11 @@ const getColor = (color) => {
|
||||
};
|
||||
|
||||
const Box = styled(View)`
|
||||
flex-direction: ${(props) => props.layout === 'column' ? 'column' : 'row'};
|
||||
padding: ${(props) => props.outer ? '4px' : '0'};
|
||||
height: ${(props) => props.fixed ? '20px' : 'auto'};
|
||||
width: ${(props) => props.fixed ? '20px' : 'auto'};
|
||||
background-color: ${(props) => getColor(props.color)};
|
||||
flex-direction: ${props => props.layout === 'column' ? 'column' : 'row'};
|
||||
padding: ${props => props.outer ? '4px' : '0'};
|
||||
height: ${props => props.fixed ? '20px' : 'auto'};
|
||||
width: ${props => props.fixed ? '20px' : 'auto'};
|
||||
background-color: ${props => getColor(props.color)};
|
||||
`;
|
||||
|
||||
module.exports = Box;
|
||||
|
||||
@@ -23,6 +23,4 @@ const tests = [
|
||||
];
|
||||
|
||||
// run benchmarks
|
||||
tests.reduce((promise, test) => {
|
||||
return promise.then(test());
|
||||
}, Promise.resolve());
|
||||
tests.reduce((promise, test) => promise.then(test()), Promise.resolve());
|
||||
|
||||
@@ -14,29 +14,20 @@ class DeepTree extends Component {
|
||||
const { Box } = components;
|
||||
|
||||
let result = (
|
||||
<Box
|
||||
color={id % 3}
|
||||
components={components}
|
||||
layout={depth % 2 === 0 ? 'column' : 'row'}
|
||||
outer
|
||||
>
|
||||
{depth === 0 && (
|
||||
<Box
|
||||
color={(id % 3) + 3}
|
||||
components={components}
|
||||
fixed
|
||||
/>
|
||||
)}
|
||||
{depth !== 0 && Array.from({ length: breadth }).map((el, i) => (
|
||||
<DeepTree
|
||||
breadth={breadth}
|
||||
components={components}
|
||||
depth={depth - 1}
|
||||
id={i}
|
||||
key={i}
|
||||
wrap={wrap}
|
||||
/>
|
||||
))}
|
||||
<Box color={id % 3} components={components} layout={depth % 2 === 0 ? 'column' : 'row'} outer>
|
||||
{depth === 0 && <Box color={id % 3 + 3} components={components} fixed />}
|
||||
{depth !== 0 &&
|
||||
Array.from({ length: breadth })
|
||||
.map((el, i) => (
|
||||
<DeepTree
|
||||
breadth={breadth}
|
||||
components={components}
|
||||
depth={depth - 1}
|
||||
id={i}
|
||||
key={i}
|
||||
wrap={wrap}
|
||||
/>
|
||||
))}
|
||||
</Box>
|
||||
);
|
||||
for (let i = 0; i < wrap; i++) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as marky from 'marky';
|
||||
|
||||
const fmt = (time) => `${Math.round(time * 100) / 100}ms`;
|
||||
const fmt = time => `${Math.round(time * 100) / 100}ms`;
|
||||
|
||||
const measure = (name, fn) => {
|
||||
marky.mark(name);
|
||||
@@ -9,23 +9,27 @@ const measure = (name, fn) => {
|
||||
return performanceMeasure.duration;
|
||||
};
|
||||
|
||||
const mean = (values) => {
|
||||
const mean = values => {
|
||||
const sum = values.reduce((sum, value) => sum + value, 0);
|
||||
return sum / values.length;
|
||||
};
|
||||
|
||||
const median = (values) => {
|
||||
if (!Array.isArray(values)) { return 0; }
|
||||
if (values.length === 1) { return values[0]; }
|
||||
const median = values => {
|
||||
if (!Array.isArray(values)) {
|
||||
return 0;
|
||||
}
|
||||
if (values.length === 1) {
|
||||
return values[0];
|
||||
}
|
||||
|
||||
const numbers = [ ...values ].sort((a, b) => a - b);
|
||||
return (numbers[(numbers.length - 1) >> 1] + numbers[numbers.length >> 1]) / 2;
|
||||
const numbers = [...values].sort((a, b) => a - b);
|
||||
return (numbers[numbers.length - 1 >> 1] + numbers[numbers.length >> 1]) / 2;
|
||||
};
|
||||
|
||||
const standardDeviation = (values) => {
|
||||
const standardDeviation = values => {
|
||||
const avg = mean(values);
|
||||
|
||||
const squareDiffs = values.map((value) => {
|
||||
const squareDiffs = values.map(value => {
|
||||
const diff = value - avg;
|
||||
return diff * diff;
|
||||
});
|
||||
@@ -35,7 +39,7 @@ const standardDeviation = (values) => {
|
||||
};
|
||||
|
||||
const benchmark = ({ name, description, setup, teardown, task, runs }) => {
|
||||
return new Promise((resolve) => {
|
||||
return new Promise(resolve => {
|
||||
const durations = [];
|
||||
let i = 0;
|
||||
|
||||
|
||||
@@ -6,15 +6,7 @@ const renderDeepTree = (label, components) => createRenderBenchmark({
|
||||
name: `Deep tree [${label}]`,
|
||||
runs: 20,
|
||||
getElement() {
|
||||
return (
|
||||
<NestedTree
|
||||
breadth={3}
|
||||
components={components}
|
||||
depth={6}
|
||||
id={0}
|
||||
wrap={1}
|
||||
/>
|
||||
);
|
||||
return <NestedTree breadth={3} components={components} depth={6} id={0} wrap={1} />;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -6,15 +6,7 @@ const renderWideTree = (label, components) => createRenderBenchmark({
|
||||
name: `Wide tree [${label}]`,
|
||||
runs: 20,
|
||||
getElement() {
|
||||
return (
|
||||
<NestedTree
|
||||
breadth={10}
|
||||
components={components}
|
||||
depth={3}
|
||||
id={0}
|
||||
wrap={4}
|
||||
/>
|
||||
);
|
||||
return <NestedTree breadth={10} components={components} depth={3} id={0} wrap={4} />;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -28,7 +28,9 @@ module.exports = {
|
||||
analyzerMode: 'static',
|
||||
openAnalyzer: false
|
||||
}),
|
||||
new webpack.DefinePlugin({ 'process.env.NODE_ENV': JSON.stringify('production') }),
|
||||
new webpack.DefinePlugin({
|
||||
'process.env.NODE_ENV': JSON.stringify('production')
|
||||
}),
|
||||
new webpack.optimize.DedupePlugin(),
|
||||
new webpack.optimize.OccurenceOrderPlugin(),
|
||||
new webpack.optimize.UglifyJsPlugin({
|
||||
|
||||
Reference in New Issue
Block a user