Skip to content
Snippets Groups Projects
Unverified Commit 3f73c6df authored by Michael "Z" Goddard's avatar Michael "Z" Goddard
Browse files

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.
parent 6d5183f9
No related branches found
No related tags found
No related merge requests found
...@@ -74,7 +74,7 @@ const vmListenerHOC = function (WrappedComponent) { ...@@ -74,7 +74,7 @@ const vmListenerHOC = function (WrappedComponent) {
} }
} }
handleProjectChanged () { handleProjectChanged () {
if (this.props.shouldEmitUpdates) { if (this.props.shouldEmitUpdates && !this.props.projectChanged) {
this.props.onProjectChanged(); this.props.onProjectChanged();
} }
} }
...@@ -117,6 +117,7 @@ const vmListenerHOC = function (WrappedComponent) { ...@@ -117,6 +117,7 @@ const vmListenerHOC = function (WrappedComponent) {
const { const {
/* eslint-disable no-unused-vars */ /* eslint-disable no-unused-vars */
attachKeyboardEvents, attachKeyboardEvents,
projectChanged,
shouldEmitUpdates, shouldEmitUpdates,
onBlockDragUpdate, onBlockDragUpdate,
onGreenFlag, onGreenFlag,
...@@ -154,6 +155,7 @@ const vmListenerHOC = function (WrappedComponent) { ...@@ -154,6 +155,7 @@ const vmListenerHOC = function (WrappedComponent) {
onTargetsUpdate: PropTypes.func.isRequired, onTargetsUpdate: PropTypes.func.isRequired,
onTurboModeOff: PropTypes.func.isRequired, onTurboModeOff: PropTypes.func.isRequired,
onTurboModeOn: PropTypes.func.isRequired, onTurboModeOn: PropTypes.func.isRequired,
projectChanged: PropTypes.bool,
shouldEmitUpdates: PropTypes.bool, shouldEmitUpdates: PropTypes.bool,
username: PropTypes.string, username: PropTypes.string,
vm: PropTypes.instanceOf(VM).isRequired vm: PropTypes.instanceOf(VM).isRequired
...@@ -163,6 +165,7 @@ const vmListenerHOC = function (WrappedComponent) { ...@@ -163,6 +165,7 @@ const vmListenerHOC = function (WrappedComponent) {
onGreenFlag: () => ({}) onGreenFlag: () => ({})
}; };
const mapStateToProps = state => ({ const mapStateToProps = state => ({
projectChanged: state.scratchGui.projectChanged,
// Do not emit target or project updates in fullscreen or player only mode // 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) // or when recording sounds (it leads to garbled recordings on low-power machines)
shouldEmitUpdates: !state.scratchGui.mode.isFullScreen && !state.scratchGui.mode.isPlayerOnly && shouldEmitUpdates: !state.scratchGui.mode.isFullScreen && !state.scratchGui.mode.isPlayerOnly &&
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment