Animatron/player — pull request #44 by shamansir (2012-09-03 18:06:09+00:00)
Title: Remove-safe iteration + Clearing/Detaching the Element

New incoming features:

* `b().iter(func)` — Almost the same as `.each(func)`, but uses the iterator object internally, instead of plain for-loop, so it is safe to remove something among the element's children, but in special way: by returning `false` from the function:

var root = b();
root.add(b('foo')).add(b('bar'));
root.iter(function(elm) {
return (elm.name == 'foo'); // will safely remove 'bar'
});
console.log(root.v.children.length); // 1
console.log(root.v.children[0].name); // 'foo'

// omitting return statement affects nothing and acts as `each`,
// but may be a bit slowly because of iterator object
var root = b();
root.add(b('foo')).add(b('bar'));
root.iter(function(elm) {
console.log(elm.name); // foo, bar
});
console.log(root.v.children.length); // 2
console.log(root.v.children[0].name); // 'foo'
console.log(root.v.children[1].name); // 'bar'

* `b().diter(func)` — The same as below, but goes deep to grand`*`-children.

* `b().clear()` — detaches all children elements from this element and from scene (grand-children stay attached to their parent, but also removed from scene). Long-awaited one, I know. Don't use while iterating over the parent (you'll get an error now, anyway).

* `b().detach()` — detaches this element from its parent and scene. All its grand-children keep it as a parent, but are also detached from scene.

Tests included, Error reporting improved, especially for unsafe removing while iterating over elements.