Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use cached noop function #33496

Merged
merged 5 commits into from Apr 11, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions js/src/dropdown.js
Expand Up @@ -192,7 +192,7 @@ class Dropdown extends BaseComponent {
if ('ontouchstart' in document.documentElement &&
!parent.closest(SELECTOR_NAVBAR_NAV)) {
[].concat(...document.body.children)
.forEach(elem => EventHandler.on(elem, 'mouseover', null, noop()))
.forEach(elem => EventHandler.on(elem, 'mouseover', noop))
}

this._element.focus()
Expand Down Expand Up @@ -222,7 +222,7 @@ class Dropdown extends BaseComponent {
// empty mouseover listeners we added for iOS support
if ('ontouchstart' in document.documentElement) {
[].concat(...document.body.children)
.forEach(elem => EventHandler.off(elem, 'mouseover', null, noop()))
.forEach(elem => EventHandler.off(elem, 'mouseover', noop))
}

if (this._popper) {
Expand Down Expand Up @@ -435,7 +435,7 @@ class Dropdown extends BaseComponent {
// empty mouseover listeners we added for iOS support
if ('ontouchstart' in document.documentElement) {
[].concat(...document.body.children)
.forEach(elem => EventHandler.off(elem, 'mouseover', null, noop()))
.forEach(elem => EventHandler.off(elem, 'mouseover', noop))
}

if (context._popper) {
Expand Down
2 changes: 1 addition & 1 deletion js/src/tooltip.js
Expand Up @@ -301,7 +301,7 @@ class Tooltip extends BaseComponent {
// https://www.quirksmode.org/blog/archives/2014/02/mouse_event_bub.html
if ('ontouchstart' in document.documentElement) {
[].concat(...document.body.children).forEach(element => {
EventHandler.on(element, 'mouseover', noop())
EventHandler.on(element, 'mouseover', noop)
})
}

Expand Down
2 changes: 1 addition & 1 deletion js/src/util/index.js
Expand Up @@ -190,7 +190,7 @@ const findShadowRoot = element => {
return findShadowRoot(element.parentNode)
}

const noop = () => function () {}
const noop = () => {}

const reflow = element => element.offsetHeight

Expand Down
5 changes: 3 additions & 2 deletions js/tests/unit/dropdown.spec.js
@@ -1,5 +1,6 @@
import Dropdown from '../../src/dropdown'
import EventHandler from '../../src/dom/event-handler'
import { noop } from '../../src/util'

/** Test helpers */
import { getFixture, clearFixture, createEvent, jQueryMock } from '../helpers/fixture'
Expand Down Expand Up @@ -252,15 +253,15 @@ describe('Dropdown', () => {
btnDropdown.addEventListener('shown.bs.dropdown', () => {
expect(btnDropdown.classList.contains('show')).toEqual(true)
expect(btnDropdown.getAttribute('aria-expanded')).toEqual('true')
expect(EventHandler.on).toHaveBeenCalled()
expect(EventHandler.on).toHaveBeenCalledWith(jasmine.any(Object), 'mouseover', noop)

dropdown.toggle()
})

btnDropdown.addEventListener('hidden.bs.dropdown', () => {
expect(btnDropdown.classList.contains('show')).toEqual(false)
expect(btnDropdown.getAttribute('aria-expanded')).toEqual('false')
expect(EventHandler.off).toHaveBeenCalled()
expect(EventHandler.off).toHaveBeenCalledWith(jasmine.any(Object), 'mouseover', noop)

document.documentElement.ontouchstart = defaultValueOnTouchStart
done()
Expand Down
4 changes: 2 additions & 2 deletions js/tests/unit/tooltip.spec.js
Expand Up @@ -450,7 +450,7 @@ describe('Tooltip', () => {

tooltipEl.addEventListener('shown.bs.tooltip', () => {
expect(document.querySelector('.tooltip')).not.toBeNull()
expect(EventHandler.on).toHaveBeenCalled()
expect(EventHandler.on).toHaveBeenCalledWith(jasmine.any(Object), 'mouseover', noop)
document.documentElement.ontouchstart = undefined
done()
})
Expand Down Expand Up @@ -889,7 +889,7 @@ describe('Tooltip', () => {

tooltipEl.addEventListener('hidden.bs.tooltip', () => {
expect(document.querySelector('.tooltip')).toBeNull()
expect(EventHandler.off).toHaveBeenCalled()
expect(EventHandler.off).toHaveBeenCalledWith(jasmine.any(Object), 'mouseover', noop)
document.documentElement.ontouchstart = undefined
done()
})
Expand Down
4 changes: 2 additions & 2 deletions js/tests/unit/util/index.spec.js
Expand Up @@ -477,8 +477,8 @@ describe('Util', () => {
})

describe('noop', () => {
it('should return a function', () => {
expect(typeof Util.noop()).toEqual('function')
it('should be a function', () => {
expect(typeof Util.noop).toEqual('function')
})
})

Expand Down