Skip to content

Commit c721288

Browse files
committed
Get rid of EventBasedRemovalTracker
It seems like it's a bad idea to support MutationEvent-based removal tracker. https://developer.mozilla.org/en-US/docs/Web/API/MutationEvent According to the document above, there are a lot of issues with MutationEvents, and they are even not broadly supported in browsers. Mutation observer polyfill: https://github.com/Polymer/MutationObservers
1 parent 3cc17b0 commit c721288

File tree

2 files changed

+2
-43
lines changed

2 files changed

+2
-43
lines changed

src/decorators/trackRemoval.js

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -9,39 +9,7 @@ const isMutationObserverAvailable = () => {
99
return getMutationObserverClass() != null
1010
}
1111

12-
class EventBasedRemovalTracker {
13-
constructor (tooltip) {
14-
this.tooltip = tooltip
15-
this.listeners = []
16-
}
17-
18-
attach (element) {
19-
const {tooltip} = this
20-
21-
const listener = (e) => {
22-
if (e.currentTarget === tooltip.state.currentTarget) {
23-
tooltip.hideTooltip()
24-
this.listeners.splice(this.listeners.indexOf(listener), 1)
25-
}
26-
}
27-
28-
this.listeners.push({
29-
element,
30-
listener
31-
})
32-
33-
element.addEventListener('DOMNodeRemovedFromDocument', listener)
34-
}
35-
36-
unbind () {
37-
for (const {listener, element} of this.listeners) {
38-
element.removeEventListener('DOMNodeRemovedFromDocument', listener)
39-
}
40-
this.listeners = []
41-
}
42-
}
43-
44-
class MutationBasedRemovalTracker {
12+
class ObserverBasedRemovalTracker {
4513
constructor (tooltip) {
4614
this.tooltip = tooltip
4715

@@ -86,16 +54,8 @@ class MutationBasedRemovalTracker {
8654
export default function (target) {
8755
target.prototype.bindRemovalTracker = function () {
8856
if (isMutationObserverAvailable()) {
89-
this.removalTracker = new MutationBasedRemovalTracker(this)
57+
this.removalTracker = new ObserverBasedRemovalTracker(this)
9058
this.removalTracker.init()
91-
} else {
92-
this.removalTracker = new EventBasedRemovalTracker(this)
93-
}
94-
}
95-
96-
target.prototype.attachRemovalTracker = function (element) {
97-
if (this.removalTracker.attach) {
98-
this.removalTracker.attach(element)
9959
}
10060
}
10161

src/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,6 @@ class ReactTooltip extends Component {
189189
target.addEventListener('mousemove', this.updateTooltip, isCaptureMode)
190190
}
191191
target.addEventListener('mouseleave', this.hideTooltip, isCaptureMode)
192-
this.attachRemovalTracker(target)
193192
})
194193

195194
// Global event to hide tooltip

0 commit comments

Comments
 (0)