Skip to content

Commit

Permalink
Simplify onClick handler
Browse files Browse the repository at this point in the history
  • Loading branch information
jsnmoon committed Oct 14, 2019
1 parent 52ae4a6 commit a0c6a97
Showing 1 changed file with 3 additions and 17 deletions.
20 changes: 3 additions & 17 deletions modules/search/instant-search/components/search-result-minimal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,9 @@ class SearchResultMinimal extends Component {
};
}

onClick = event => {
// User-triggered event
if ( event.isTrusted ) {
event.stopPropagation();
event.preventDefault();
// Send out analytics call
recordTrainTracksInteract( { ...this.getCommonTrainTracksProps(), action: 'click' } );
// Await next animation frame to ensure w.js processes the queue
requestAnimationFrame( () => {
// Re-dispatch click event
const clonedEvent = new event.constructor( event.type, event );
event.target.dispatchEvent( clonedEvent );
} );
} else {
// Programmatically dispatched event from `dispatchEvent`
return true;
}
onClick = () => {
// Send out analytics call
recordTrainTracksInteract( { ...this.getCommonTrainTracksProps(), action: 'click' } );
};

render() {
Expand Down

0 comments on commit a0c6a97

Please sign in to comment.