Skip to content

Commit

Permalink
load only if mounted
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeburns committed Mar 13, 2018
1 parent e7c3305 commit d4d2ccd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ if (window && window.MutationObserver) {
eachMutation(mutations[i].removedNodes, function (index, el) {
if (!document.documentElement.contains(el)) turnoff(index, el)
})
eachMutation(mutations[i].addedNodes, turnon)
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 d4d2ccd

Please sign in to comment.