[js] optimize object allocations

This commit is contained in:
Mikael Sand
2019-03-10 03:39:30 +02:00
parent fad190a283
commit bd6ffcafe3
3 changed files with 55 additions and 70 deletions
+12 -18
View File
@@ -15,29 +15,23 @@ export default class TSpan extends Shape {
props.matrix = matrix;
}
const prop = propsAndStyles(props);
const text = pickNotNil(extractText(prop, false));
this.root.setNativeProps({
...prop,
...text,
});
Object.assign(prop, pickNotNil(extractText(prop, false)));
this.root.setNativeProps(prop);
};
render() {
const prop = propsAndStyles(this.props);
return (
<RNSVGTSpan
ref={this.refMethod}
{...extractProps(
{
...prop,
x: null,
y: null,
},
this,
)}
{...extractText(prop, false)}
/>
const props = extractProps(
{
...prop,
x: null,
y: null,
},
this,
);
Object.assign(props, extractText(prop, false));
props.ref = this.refMethod;
return <RNSVGTSpan {...props} />;
}
}
+12 -18
View File
@@ -16,29 +16,23 @@ export default class Text extends Shape {
props.matrix = matrix;
}
const prop = propsAndStyles(props);
const text = pickNotNil(extractText(prop, true));
this.root.setNativeProps({
...prop,
...text,
});
Object.assign(prop, pickNotNil(extractText(prop, true)));
this.root.setNativeProps(prop);
};
render() {
const prop = propsAndStyles(this.props);
return (
<RNSVGText
ref={this.refMethod}
{...extractProps(
{
...prop,
x: null,
y: null,
},
this,
)}
{...extractText(prop, true)}
/>
const props = extractProps(
{
...prop,
x: null,
y: null,
},
this,
);
Object.assign(props, extractText(prop, true));
props.ref = this.refMethod;
return <RNSVGText {...props} />;
}
}
+31 -34
View File
@@ -15,11 +15,8 @@ export default class TextPath extends Shape {
if (matrix) {
props.matrix = matrix;
}
const text = pickNotNil(extractText(props, true));
this.root.setNativeProps({
...props,
...text,
});
Object.assign(props, pickNotNil(extractText(props, true)));
this.root.setNativeProps(props);
};
render() {
@@ -27,45 +24,45 @@ export default class TextPath extends Shape {
children,
xlinkHref,
href = xlinkHref,
startOffset,
startOffset = 0,
method,
spacing,
side,
alignmentBaseline,
midLine,
...props
...prop
} = this.props;
const matched = href && href.match(idPattern);
const match = matched && matched[1];
if (match) {
return (
<RNSVGTextPath
ref={this.refMethod}
{...extractProps(
{
...propsAndStyles(props),
x: null,
y: null,
},
this,
)}
{...extractText(
{
children,
},
true,
)}
{...{
href: match,
startOffset: startOffset || 0,
method,
spacing,
side,
alignmentBaseline,
midLine,
}}
/>
const props = extractProps(
{
...propsAndStyles(prop),
x: null,
y: null,
},
this,
);
Object.assign(
props,
extractText(
{
children,
},
true,
),
{
href: match,
startOffset,
method,
spacing,
side,
alignmentBaseline,
midLine,
},
);
props.ref = this.refMethod;
return <RNSVGTextPath {...props} />;
}
console.warn(