Skip to content

Commit 3f73c6d

Browse files
committed
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.
1 parent 6d5183f commit 3f73c6d

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/lib/vm-listener-hoc.jsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ const vmListenerHOC = function (WrappedComponent) {
7474
}
7575
}
7676
handleProjectChanged () {
77-
if (this.props.shouldEmitUpdates) {
77+
if (this.props.shouldEmitUpdates && !this.props.projectChanged) {
7878
this.props.onProjectChanged();
7979
}
8080
}
@@ -117,6 +117,7 @@ const vmListenerHOC = function (WrappedComponent) {
117117
const {
118118
/* eslint-disable no-unused-vars */
119119
attachKeyboardEvents,
120+
projectChanged,
120121
shouldEmitUpdates,
121122
onBlockDragUpdate,
122123
onGreenFlag,
@@ -154,6 +155,7 @@ const vmListenerHOC = function (WrappedComponent) {
154155
onTargetsUpdate: PropTypes.func.isRequired,
155156
onTurboModeOff: PropTypes.func.isRequired,
156157
onTurboModeOn: PropTypes.func.isRequired,
158+
projectChanged: PropTypes.bool,
157159
shouldEmitUpdates: PropTypes.bool,
158160
username: PropTypes.string,
159161
vm: PropTypes.instanceOf(VM).isRequired
@@ -163,6 +165,7 @@ const vmListenerHOC = function (WrappedComponent) {
163165
onGreenFlag: () => ({})
164166
};
165167
const mapStateToProps = state => ({
168+
projectChanged: state.scratchGui.projectChanged,
166169
// Do not emit target or project updates in fullscreen or player only mode
167170
// or when recording sounds (it leads to garbled recordings on low-power machines)
168171
shouldEmitUpdates: !state.scratchGui.mode.isFullScreen && !state.scratchGui.mode.isPlayerOnly &&

0 commit comments

Comments
 (0)