Skip to content

Commit fe495f2

Browse files
author
Pietro
authored
Develop branch - should component update refactor (#182)
* Refactor should component updatre for transcript editor * Refactor should component updatre for PlayerControls * Refactor should component updatre for TimeBox * Refactor should component update for ProgressBar * Refactor should component update for TimedTextEditor * Refactor should component update for Header
1 parent 3588b26 commit fe495f2

File tree

6 files changed

+10
-138
lines changed

6 files changed

+10
-138
lines changed

packages/components/media-player/src/PlayerControls/TimeBox.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
import React from 'react';
2-
import PropTypes from 'prop-types';
32
import style from './index.module.css';
43

54
class TimeBox extends React.Component {
65

76
shouldComponentUpdate(nextProps) {
8-
if (nextProps.currentTime !== this.props.currentTime) {
9-
return true;
10-
}
11-
if (nextProps.duration !== this.props.duration) {
7+
if (nextProps !== this.props) {
128
return true;
139
}
1410

1511
return false;
1612
}
13+
1714
// as separate function above render for performance
1815
handleClick = (e) => {
1916
this.props.promptSetCurrentTime(e);

packages/components/media-player/src/PlayerControls/index.js

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,8 @@ import TimeBox from './TimeBox.js';
2121

2222
class PlayerControls extends React.Component {
2323

24-
shouldComponentUpdate(nextProps) {
25-
if (nextProps.currentTime !== this.props.currentTime) {
26-
return true;
27-
}
28-
if (nextProps.duration !== this.props.duration) {
29-
return true;
30-
}
31-
32-
if (nextProps.playbackRate !== this.props.playbackRate) {
33-
return true;
34-
}
35-
36-
if (nextProps.isPlaying !== this.props.isPlaying) {
37-
return true;
38-
}
39-
40-
if (nextProps.isMute !== this.props.isMute) {
41-
return true;
42-
}
24+
shouldComponentUpdate = (nextProps) => {
25+
if (nextProps !== this.props) return true;
4326

4427
return false;
4528
}

packages/components/media-player/src/ProgressBar.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,7 @@ class ProgressBar extends React.Component {
77

88
// performance optimization
99
shouldComponentUpdate = (nextProps) => {
10-
if (nextProps.buttonClick !== this.props.buttonClick) {
11-
return true;
12-
}
13-
14-
if (nextProps.value !== this.props.value) {
15-
return true;
16-
}
17-
18-
if (nextProps.max !== this.props.max) {
10+
if (nextProps !== this.props) {
1911
return true;
2012
}
2113

packages/components/timed-text-editor/index.js

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -37,46 +37,9 @@ class TimedTextEditor extends React.Component {
3737
}
3838

3939
shouldComponentUpdate = (nextProps, nextState) => {
40-
if (nextProps.transcriptData !== this.props.transcriptData) {
41-
return true;
42-
}
43-
44-
if (nextProps.isEditable !== this.props.isEditable) {
45-
return true;
46-
}
47-
48-
if (nextProps.timecodeOffset !== this.props.timecodeOffset) {
49-
return true;
50-
}
51-
52-
if (nextProps.showSpeakers !== this.props.showSpeakers) {
53-
return true;
54-
}
55-
56-
if (nextProps.showTimecodes !== this.props.showTimecodes) {
57-
return true;
58-
}
40+
if (nextProps !== this.props) return true;
5941

60-
if (nextProps.fileName !== this.props.fileName) {
61-
return true;
62-
}
63-
64-
// updating TimedTextEditor on every currentTime causes re-renders
65-
if (nextProps.currentTime !== this.props.currentTime ) {
66-
return true;
67-
}
68-
69-
if (nextState.editorState !== this.state.editorState ) {
70-
return true;
71-
}
72-
73-
if (nextProps.spellCheck !== this.props.spellCheck) {
74-
return true;
75-
}
76-
77-
if (nextProps.isPauseWhileTypingOn !== this.props.isPauseWhileTypingOn) {
78-
return true;
79-
}
42+
if (nextState !== this.state ) return true;
8043

8144
return false;
8245
}

packages/components/transcript-editor/index.js

Lines changed: 2 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -65,63 +65,9 @@ class TranscriptEditor extends React.Component {
6565

6666
// performance optimization
6767
shouldComponentUpdate = (nextProps, nextState) => {
68+
if (nextProps.mediaUrl !== this.props.mediaUrl) return true;
6869

69-
if (nextState.transcriptData !== this.state.transcriptData) {
70-
return true;
71-
}
72-
73-
if (nextProps.mediaUrl !== this.props.mediaUrl) {
74-
return true;
75-
}
76-
77-
if (nextState.currentTime !== this.state.currentTime) {
78-
return true;
79-
}
80-
81-
if (nextState.isScrollIntoViewOn !== this.state.isScrollIntoViewOn) {
82-
return true;
83-
}
84-
85-
if (nextState.showSettings !== this.state.showSettings) {
86-
return true;
87-
}
88-
89-
if (nextState.showShortcuts !== this.state.showShortcuts) {
90-
return true;
91-
}
92-
if (nextState.showExportOptions !== this.state.showExportOptions) {
93-
return true;
94-
}
95-
96-
if (nextState.isPauseWhileTypingOn !== this.state.isPauseWhileTypingOn) {
97-
return true;
98-
}
99-
100-
if (nextState.rollBackValueInSeconds !== this.state.rollBackValueInSeconds) {
101-
return true;
102-
}
103-
104-
if (nextState.timecodeOffset !== this.state.timecodeOffset) {
105-
return true;
106-
}
107-
108-
if (nextState.showTimecodes !== this.state.showTimecodes) {
109-
return true;
110-
}
111-
112-
if (nextState.showSpeakers !== this.state.showSpeakers) {
113-
return true;
114-
}
115-
116-
if (nextState.previewIsDisplayed !== this.state.previewIsDisplayed) {
117-
return true;
118-
}
119-
120-
if (nextState.mediaDuration !== this.state.mediaDuration) {
121-
return true;
122-
}
123-
124-
return false;
70+
return nextState !== this.state;
12571
}
12672

12773
componentDidUpdate(prevProps, prevState) {

packages/components/transcript-editor/src/Header.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,7 @@ class Header extends React.Component {
1212

1313
// to avoid unnecessary re-renders
1414
shouldComponentUpdate(nextProps) {
15-
if (nextProps.showSettings !== this.props.showSettings) {
16-
return true;
17-
}
18-
if (nextProps.showShortcuts !== this.props.showShortcuts) {
19-
return true;
20-
}
21-
22-
if (nextProps.mediaControls !== this.props.mediaControls) {
23-
return true;
24-
}
15+
if (nextProps !== this.props) return true;
2516

2617
return false;
2718
}

0 commit comments

Comments
 (0)