Skip to content

Instantly share code, notes, and snippets.

@techwraith
Last active November 19, 2017 00:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save techwraith/8049216 to your computer and use it in GitHub Desktop.
Save techwraith/8049216 to your computer and use it in GitHub Desktop.
var Renderer = function () {
var self = this
, requestAnimationFrame = window.requestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.msRequestAnimationFrame
this.queue = {}
requestAnimationFrame(function () {
self.onFrame()
})
}
var inSubviews = function (parent, child) {
return !!parent.subviews[child.cid]
}
var recurseSubviews = function (view, target) {
if (inSubviews(view, target)) return true
for (var i in view.subviews) {
if (inSubviews(view.subviews[i], target)) return true
if (recurseSubviews(view.subviews[i], target)) return true
}
return false
}
Renderer.prototype.getViewsAtLevel = function (level) {
// get all the views at a certain "level"
// if this view has no parent, it is level zero
// if it has 2 parents, it is level 2, etc.
}
Renderer.prototype.getDepth = function () {
// find the level of the view with the most parents
}
Renderer.prototype.willRenderParent = function (view) {
for (var i in this.queue) {
if (recurseSubviews(this.queue[i], view)) return true
}
return false
}
Renderer.prototype.render = function (view) {
this.queue[view.cid] = view
}
Renderer.prototype.onFrame = function () {
// go through levels from zero to last
// remove their children from the render queue
// render them, remove them from the queue
// then render the next level (if any)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment