quilljs/quill — pull request #223 by leoasis (2014-10-02 02:16:02+00:00)
Title: destroy() method for Quill instances

This PR tackles #138.

This is the core `destroy` implementation, it still doesn't clean up modules, but as you can see it will call the `destroy` method on them if they define it.
I've reached a point where we need to define a couple of things.
First, we need to decide what the state of the container must be like after destroying. Should we empty it? Should we reset it to the original html? Should we leave the html as it was at the moment of destroying?
Second, you will notice that I still have a commented test that verifies that we're removing the "focus" event listener on the iframe container in the `Editor`. Since there is no `off` method implemented in the `dom` util, we need to have something for this. I have two ideas:
1. Implement `off` by tracking the real listener and the wrapped listener in the `Wrapper` class, and calling `removeEventListener` with the same function that `addEventListener` was called with. For this to work we need to use the same instance of the `Wrapper` class, so things like `dom(elem).on('focus', something); dom(elem).off('focus', something)` won't work.
2. Change the `on` method to return a function that will remove the listener, instead of returning the `Wrapper` instance. This is very helpful since you don't need to store all the listeners in a separate variable in order to reference the same function when calling `off`. Here, `off` will be called by you with the correct listener when you call the returning function from `on`. Also, I think there are no cases of `on` being chained with other methods, so this shouldn't break existing usage.

Let me know what you think! Open to more ideas or things I've missed!