dispatch projectChange redux action when project has not changed
Dispatching a message through redux makes it reconsider all currently listening components. Dispatching for each block, while loading, can mean dispatching and reconsidering thousands of times if not more. While dispatching is pretty quick doing this for every block ends up taking a lot of time.
This commit is contained in:
1 file changed
+4
-1
@@ -74,7 +74,7 @@ const vmListenerHOC = function (WrappedComponent) {
|
||||
}
|
||||
}
|
||||
handleProjectChanged () {
|
||||
if (this.props.shouldEmitUpdates) {
|
||||
if (this.props.shouldEmitUpdates && !this.props.projectChanged) {
|
||||
this.props.onProjectChanged();
|
||||
}
|
||||
}
|
||||
@@ -117,6 +117,7 @@ const vmListenerHOC = function (WrappedComponent) {
|
||||
const {
|
||||
/* eslint-disable no-unused-vars */
|
||||
attachKeyboardEvents,
|
||||
projectChanged,
|
||||
shouldEmitUpdates,
|
||||
onBlockDragUpdate,
|
||||
onGreenFlag,
|
||||
@@ -154,6 +155,7 @@ const vmListenerHOC = function (WrappedComponent) {
|
||||
onTargetsUpdate: PropTypes.func.isRequired,
|
||||
onTurboModeOff: PropTypes.func.isRequired,
|
||||
onTurboModeOn: PropTypes.func.isRequired,
|
||||
projectChanged: PropTypes.bool,
|
||||
shouldEmitUpdates: PropTypes.bool,
|
||||
username: PropTypes.string,
|
||||
vm: PropTypes.instanceOf(VM).isRequired
|
||||
@@ -163,6 +165,7 @@ const vmListenerHOC = function (WrappedComponent) {
|
||||
onGreenFlag: () => ({})
|
||||
};
|
||||
const mapStateToProps = state => ({
|
||||
projectChanged: state.scratchGui.projectChanged,
|
||||
// Do not emit target or project updates in fullscreen or player only mode
|
||||
// or when recording sounds (it leads to garbled recordings on low-power machines)
|
||||
shouldEmitUpdates: !state.scratchGui.mode.isFullScreen && !state.scratchGui.mode.isPlayerOnly &&
|
||||
|
||||
Reference in new issue
Block a user