This PR makes it so the MutationObserver only kicks off if/after the DOM has fully loaded.
Rationale
This prevents issues when document.body isn't present for any reason. One might argue that it is the developer's responsibility to ensure that the code doesn't execute before body exists. I think it's better to account for that in the module itself.
Likely fixes #14
Implementation notes
Using DOMContentLoaded and checking for complete readystate because I'm assuming you don't support <IE10 anyway.
Using a higher-order function for the event handler for purity and the good of all humankind.
Checklist
[x] tests: 19/19 passed
[x] style: node node_modules/.bin/standard does not return any warnings
This PR makes it so the
MutationObserver
only kicks off if/after the DOM has fully loaded.Rationale
This prevents issues when
document.body
isn't present for any reason. One might argue that it is the developer's responsibility to ensure that the code doesn't execute beforebody
exists. I think it's better to account for that in the module itself.Likely fixes #14
Implementation notes
Using
DOMContentLoaded
and checking forcomplete
readystate because I'm assuming you don't support <IE10 anyway.Using a higher-order function for the event handler for purity and the good of all humankind.
Checklist
node node_modules/.bin/standard
does not return any warnings💥