Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
logging-scratch-gui
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
David Goessmann
logging-scratch-gui
Commits
3b1e32f3
Unverified
Commit
3b1e32f3
authored
Oct 26, 2018
by
Paul Kaplan
Committed by
GitHub
Oct 26, 2018
Browse files
Options
Downloads
Plain Diff
Merge pull request #3525 from paulkaplan/prevent-targets-dispatch
Only dispatch targetsUpdate events if the full editor is visible
parents
5877c180
98303e31
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/lib/vm-listener-hoc.jsx
+21
-5
21 additions, 5 deletions
src/lib/vm-listener-hoc.jsx
with
21 additions
and
5 deletions
src/lib/vm-listener-hoc.jsx
+
21
−
5
View file @
3b1e32f3
...
...
@@ -23,7 +23,8 @@ const vmListenerHOC = function (WrappedComponent) {
super
(
props
);
bindAll
(
this
,
[
'
handleKeyDown
'
,
'
handleKeyUp
'
'
handleKeyUp
'
,
'
handleTargetsUpdate
'
]);
// We have to start listening to the vm here rather than in
// componentDidMount because the HOC mounts the wrapped component,
...
...
@@ -31,7 +32,7 @@ const vmListenerHOC = function (WrappedComponent) {
// mounts.
// If the wrapped component uses the vm in componentDidMount, then
// we need to start listening before mounting the wrapped component.
this
.
props
.
vm
.
on
(
'
targetsUpdate
'
,
this
.
props
.
on
TargetsUpdate
);
this
.
props
.
vm
.
on
(
'
targetsUpdate
'
,
this
.
handle
TargetsUpdate
);
this
.
props
.
vm
.
on
(
'
MONITORS_UPDATE
'
,
this
.
props
.
onMonitorsUpdate
);
this
.
props
.
vm
.
on
(
'
BLOCK_DRAG_UPDATE
'
,
this
.
props
.
onBlockDragUpdate
);
this
.
props
.
vm
.
on
(
'
TURBO_MODE_ON
'
,
this
.
props
.
onTurboModeOn
);
...
...
@@ -49,9 +50,15 @@ const vmListenerHOC = function (WrappedComponent) {
}
this
.
props
.
vm
.
postIOData
(
'
userData
'
,
{
username
:
this
.
props
.
username
});
}
componentWillReceiveProps
(
newProps
)
{
if
(
newProps
.
username
!==
this
.
props
.
username
)
{
this
.
props
.
vm
.
postIOData
(
'
userData
'
,
{
username
:
newProps
.
username
});
componentDidUpdate
(
prevProps
)
{
if
(
prevProps
.
username
!==
this
.
props
.
username
)
{
this
.
props
.
vm
.
postIOData
(
'
userData
'
,
{
username
:
this
.
props
.
username
});
}
// Re-request a targets update when the shouldEmitTargetsUpdate state changes to true
// i.e. when the editor transitions out of fullscreen/player only modes
if
(
this
.
props
.
shouldEmitTargetsUpdate
&&
!
prevProps
.
shouldEmitTargetsUpdate
)
{
this
.
props
.
vm
.
emitTargetsUpdate
();
}
}
componentWillUnmount
()
{
...
...
@@ -61,6 +68,11 @@ const vmListenerHOC = function (WrappedComponent) {
document
.
removeEventListener
(
'
keyup
'
,
this
.
handleKeyUp
);
}
}
handleTargetsUpdate
(
data
)
{
if
(
this
.
props
.
shouldEmitTargetsUpdate
)
{
this
.
props
.
onTargetsUpdate
(
data
);
}
}
handleKeyDown
(
e
)
{
// Don't capture keys intended for Blockly inputs.
if
(
e
.
target
!==
document
&&
e
.
target
!==
document
.
body
)
return
;
...
...
@@ -89,6 +101,7 @@ const vmListenerHOC = function (WrappedComponent) {
const
{
/* eslint-disable no-unused-vars */
attachKeyboardEvents
,
shouldEmitTargetsUpdate
,
username
,
onBlockDragUpdate
,
onKeyDown
,
...
...
@@ -120,6 +133,7 @@ const vmListenerHOC = function (WrappedComponent) {
onTargetsUpdate
:
PropTypes
.
func
.
isRequired
,
onTurboModeOff
:
PropTypes
.
func
.
isRequired
,
onTurboModeOn
:
PropTypes
.
func
.
isRequired
,
shouldEmitTargetsUpdate
:
PropTypes
.
bool
,
username
:
PropTypes
.
string
,
vm
:
PropTypes
.
instanceOf
(
VM
).
isRequired
};
...
...
@@ -127,6 +141,8 @@ const vmListenerHOC = function (WrappedComponent) {
attachKeyboardEvents
:
true
};
const
mapStateToProps
=
state
=>
({
// Do not emit target updates in fullscreen or player only mode
shouldEmitTargetsUpdate
:
!
state
.
scratchGui
.
mode
.
isFullScreen
&&
!
state
.
scratchGui
.
mode
.
isPlayerOnly
,
vm
:
state
.
scratchGui
.
vm
,
username
:
state
.
session
&&
state
.
session
.
session
&&
state
.
session
.
session
.
user
?
state
.
session
.
session
.
user
.
username
:
''
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment