Last active
August 29, 2015 14:13
-
-
Save WillsonSmith/981d259ca65db22884ec to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function checkIfNew(tagName, cb) { | |
"use strict"; | |
var nodeList = document.getElementsByTagName(tagName); | |
var tempList = [].slice.call(nodeList); | |
function conditional() { | |
var tempLength = tempList.length, | |
nodeLength = nodeList.length, | |
lastTemp = tempList[tempLength - 1], | |
lastNode = nodeList[nodeLength - 1], | |
condition = false; | |
condition = tempLength === nodeLength ? false : true; | |
//this check covers if moving item | |
condition = lastTemp === lastNode ? false : true; | |
return condition; | |
} | |
function compareTemp() { | |
if (conditional()) { //|| tempList[ tempList.length - 1 ] !== nodeList[ nodeList.length - 1 ]) { | |
tempList = [].slice.call(nodeList); | |
//may change to return diffs from a filter | |
//added or removed | |
cb(tempList); | |
} | |
window.requestAnimationFrame(compareTemp); | |
} | |
return { | |
loopList: function() { | |
window.requestAnimationFrame(compareTemp); | |
}, | |
getCurrent: function() { | |
return tempList; | |
} | |
}; | |
} | |
var x = checkIfNew("div", function(newList) { | |
console.log(newList); | |
}); | |
x.loopList(); | |
document.body.appendChild(document.createElement("div")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment