craftyjs/Crafty — pull request #501 by starwed (2013-07-02 17:43:40+00:00)
Title: Add the ability for components to run a special function on removal/destruction

Allows components to define a remove method that work similarly to `init`. It will be called when the entity is destroyed or the component is removed. It's passed a boolean flag that is true on destruction, false on simple removal.

This patch also moves the trigger of "RemoveComponent" so that it occurs before the component is removed, instead of after.