Famous/famous — pull request #153 by timjchin (2014-08-01 01:09:57+00:00)
Title: RFC: Remove added to context, view, rendernode

Solves: https://github.com/Famous/core/issues/7

There are times when developing Famo.us apps that the developer knows they are completely done with content generated in Famo.us. For those times, it is desired to have the ability to remove items from the scene graph, including complete removal from Entity.

Other than custom event cleanup, this pull request would enable developers to permanently remove items from a Context, View, or RenderNode directly.

example:
```js
var myView = new View();
var someSurface = new Surface();
myView.add(someSurface);

// at a later point
myView.remove(someSurface) // surface removed from the render tree and unregistered from entity
```
If you have a parent with multiple children, all nested entities are unregistered and removed. All deregistering / entity cleanup happens immediately.

The remove method is tested with Mocha in [this repo.](https://github.com/timjchin/removalTesting)
Currently tested:
```
BFS
One level
should find a single level surface
should find a single level modifier
shouldn't find a node not included in the tree

deep level

should find a nested surface.
should find a nested modifier.
should find a surface inside of a view
should find a surface inside of a view inside of a view
should find a surface inside of a view inside of a view inside of a view..

Removal

should remove a nested surface.
should unregister a nested surface from Entity.
should remove a portion of the render tree.
should remove a portion of the render tree inside of a view.
should remove a portion of the render tree inside of a view. Multiple surfaces.
should remove a portion of the render tree inside of a view. Multiple surfaces inside nested Views.
should unregister the portions of the render tree that were removed.

Remove From Live Famo.us

should remove a surface.
should remove a portion of the render tree.
should remove a portion of the render tree.
```

Required Changes
RenderNode is aware of it's parent. This allows faster traversal up the tree, all the way to the Context it is attached to.
RenderNode has an ID.

This implementation of remove supports Views, Modifiers, Surfaces, or items that have a renderNode as `._node`. As a caveat, components like HeaderFooterLayout would not be supported with complete cleanup. They could gain support if they conform to the View pattern of having one parent renderNode aliased as `._node`. Similar components could be refactored to support that pattern.