Skip to content

Commit b4434cd

Browse files
committed
fix: 性能优化
1 parent 72be017 commit b4434cd

File tree

3 files changed

+1359
-142
lines changed

3 files changed

+1359
-142
lines changed

package/components/SchemaComponents/SchemaJson.js

+51-46
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class SchemaArray extends PureComponent {
4747
this._tagPaddingLeftStyle = {};
4848
}
4949

50-
componentWillMount(){
50+
componentWillMount() {
5151
const { prefix } = this.props;
5252
let length = prefix.filter(name => name != 'properties').length;
5353
this.__tagPaddingLeftStyle = {
@@ -212,10 +212,10 @@ class SchemaItem extends PureComponent {
212212
constructor(props) {
213213
super(props);
214214
this._tagPaddingLeftStyle = {};
215-
this.num =0
215+
this.num = 0
216216
}
217217

218-
componentWillMount(){
218+
componentWillMount() {
219219
const { prefix } = this.props;
220220
let length = prefix.filter(name => name != 'properties').length;
221221
this.__tagPaddingLeftStyle = {
@@ -242,8 +242,8 @@ class SchemaItem extends PureComponent {
242242
this.context.changeValueAction(key, value);
243243
};
244244

245-
handleChangeDesc = (e)=>{
246-
const {data, name} = this.props
245+
handleChangeDesc = (e) => {
246+
const { data, name } = this.props
247247
this.changeValue(this.getPrefix(), `description`, e.target.value)
248248
}
249249

@@ -252,7 +252,7 @@ class SchemaItem extends PureComponent {
252252
this.context.changeTypeAction(key, value);
253253
};
254254

255-
handleChangeType = (e)=>{
255+
handleChangeType = (e) => {
256256
this.changeType(this.getPrefix(), e)
257257
}
258258

@@ -262,44 +262,44 @@ class SchemaItem extends PureComponent {
262262
this.context.enableRequireAction(prefix, name, false);
263263
};
264264

265-
handleDeleteItem = ()=>{
266-
const {prefix, name} = this.props;
265+
handleDeleteItem = () => {
266+
const { prefix, name } = this.props;
267267
this.deleteItem(prefix, name)
268268
}
269269

270-
handleShowEdit = ()=>{
271-
const {data, name, showEdit} = this.props
270+
handleShowEdit = () => {
271+
const { data, name, showEdit } = this.props
272272
showEdit(this.getPrefix(), `description`, data.properties[name].description)
273273
}
274274

275-
handleShowAdv = ()=>{
276-
const {data, name, showAdv} = this.props
275+
handleShowAdv = () => {
276+
const { data, name, showAdv } = this.props
277277
showAdv(this.getPrefix(), data.properties[name])
278278
}
279279

280-
handleAddField = ()=>{
281-
const {prefix, name} = this.props;
280+
handleAddField = () => {
281+
const { prefix, name } = this.props;
282282
this.addField(prefix, name)
283283
}
284284

285285
addField = (prefix, name) => {
286286
this.context.addFieldAction(prefix, name);
287287
};
288288

289-
getPrefix(){
289+
getPrefix() {
290290
return [].concat(this.props.prefix, this.props.name)
291291
}
292292

293-
handleClickIcon = ()=>{
293+
handleClickIcon = () => {
294294
this.clickIcon(this.getPrefix())
295295
}
296296

297-
handleEnableRequire = (e)=>{
297+
handleEnableRequire = (e) => {
298298
this.enableRequire(this.props.prefix, this.props.name, e.target.checked)
299299
}
300300

301-
handleChangeName =(e)=>{
302-
const {data, prefix, name} = this.props
301+
handleChangeName = (e) => {
302+
const { data, prefix, name } = this.props
303303
if (
304304
data.properties[e.target.value] &&
305305
typeof data.properties[e.target.value] === 'object'
@@ -410,7 +410,7 @@ class SchemaItem extends PureComponent {
410410
</Row>
411411
<div className="option-formStyle">{mapping(prefixArray, value, showEdit, showAdv)}</div>
412412
</div>
413-
): null
413+
) : null
414414
);
415415
}
416416

@@ -428,35 +428,40 @@ SchemaItem.contextTypes = {
428428
getOpenValue: PropTypes.func
429429
};
430430

431-
const SchemaObject = (props) => {
432-
const { data, prefix, showEdit, showAdv } = props;
433-
return (
434-
<div className="object-style">
435-
{Object.keys(data.properties).map((name, index) =>
436-
<SchemaItem
437-
key={index}
438-
data={props.data}
439-
name={name}
440-
prefix={prefix}
441-
showEdit={showEdit}
442-
showAdv={showAdv} />
443-
)}
444-
</div>
445-
);
431+
class SchemaObjectComponent extends PureComponent {
432+
shouldComponentUpdate(nextProps) {
433+
if (_.isEqual(nextProps.data, this.props.data)
434+
&& _.isEqual(nextProps.prefix, this.props.prefix)
435+
&& _.isEqual(nextProps.open, this.props.open)
436+
) {
437+
return false;
438+
}
439+
return true;
440+
}
446441

442+
render() {
443+
const { data, prefix, showEdit, showAdv } = this.props;
444+
return (
445+
<div className="object-style">
446+
{Object.keys(data.properties).map((name, index) =>
447+
<SchemaItem
448+
key={index}
449+
data={this.props.data}
450+
name={name}
451+
prefix={prefix}
452+
showEdit={showEdit}
453+
showAdv={showAdv} />
454+
)}
455+
</div>
456+
);
457+
}
447458
}
448459

449-
// SchemaObject.contextTypes = {
450-
// changeNameAction: PropTypes.func,
451-
// changeValueAction: PropTypes.func,
452-
// enableRequireAction: PropTypes.func,
453-
// addFieldAction: PropTypes.func,
454-
// deleteItemAction: PropTypes.func,
455-
// changeTypeAction: PropTypes.func,
456-
// addChildFieldAction: PropTypes.func,
457-
// setOpenValueAction: PropTypes.func,
458-
// getOpenValue: PropTypes.func
459-
// };
460+
const SchemaObject = connect(state => ({
461+
open: state.schema.open
462+
}))(SchemaObjectComponent)
463+
464+
460465

461466
const DropPlus = props => {
462467
const { prefix, name, add } = props;

0 commit comments

Comments
 (0)