Skip to content

Commit

Permalink
Merge pull request #35 from lukeburns/master
Browse files Browse the repository at this point in the history
unload only if not mounted
  • Loading branch information
bcomnes authored Aug 10, 2018
2 parents 932684e + d4d2ccd commit cec46f1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ if (window && window.MutationObserver) {
eachAttr(mutations[i], turnon, turnoff)
continue
}
eachMutation(mutations[i].removedNodes, turnoff)
eachMutation(mutations[i].addedNodes, turnon)
eachMutation(mutations[i].removedNodes, function (index, el) {
if (!document.documentElement.contains(el)) turnoff(index, el)
})
eachMutation(mutations[i].addedNodes, function (index, el) {
if (document.documentElement.contains(el)) turnon(index, el)
})
}
})
if (document.body) {
Expand Down
4 changes: 2 additions & 2 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ test('onload/onunload', function (t) {
el.textContent = 'test'
onload(el, function () {
t.ok(true, 'onload called')
document.body.removeChild(el)
}, function () {
t.ok(true, 'onunload called')
document.body.innerHTML = ''
t.end()
})
document.body.appendChild(el)
document.body.removeChild(el)
})

test('assign key attr', function (t) {
Expand Down Expand Up @@ -66,13 +66,13 @@ test('nested', function (t) {
var e3 = document.createElement('div')
onload(e3, function () {
t.ok(true, 'onload called')
e2.removeChild(e3)
}, function () {
t.ok(true, 'onunload called')
document.body.innerHTML = ''
t.end()
})
e2.appendChild(e3)
e2.removeChild(e3)
})

test('complex', function (t) {
Expand Down

0 comments on commit cec46f1

Please sign in to comment.