saneyuki/observer-js — pull request #32 by saneyuki (2014-02-03 04:57:36+00:00)
Title: Move the part to copying the observer's list in notify().

We call `notify()` many times than `add()`/`remove()`. We need to speed up it.

`notify()` iteration refers to the list object being on the heap.
Even if this subject modifies the list related to the topic that this handle now, it make the new list which has no effect to the list iterated now. This approach is a pseudo "copy-on-write" which is based on the assumption that all object's lifetimes are handled by garbage collection. This is tricky approach.

* When adding an observer to the same topic (calling `add()`), we don't copy the current list and add the add the observer to the current list. Although this is destructive, its operation add the observer to the end of list. So it does not effect to the current iterated range of the list's length. It's would be safety.

* When removing an observer from the same topic (calling `remove()`), we copy the current list, modify it, and overwrite this object with it. Because to remove an observer from the same topic is destructive operation that will decrease the list's length. It is not safety. See `remove()` method.

* When removing the topic and observers related to it from this subject (calling `_removeTopic()` via `removeTopic()` or `destory()`), it's not safety. However, we don't make it safe. Because, it's bad approach that the observer calls `removeTopic()` with the topic which is passed to his `handleMessange`. It should be handled in each observers with using `remove()`, or the subject handle `removeTopic/destroy`.

# TBD
- testcase