-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
destroy() method for Quill instances #223
Conversation
@@ -10,17 +10,21 @@ Tandem = require('tandem-core') | |||
class Editor | |||
constructor: (@iframeContainer, @quill, @options = {}) -> | |||
@renderer = new Renderer(@iframeContainer, @options) | |||
dom(@iframeContainer).on('focus', this.focus.bind(this)) | |||
dom(@iframeContainer).on('focus', _.bind(@focus, this)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's fine to use the lodash bind but can you keep the this.focus? I prefer to refer to functions with this and variables with ampersand
Cool thanks for the PR. Sorry for the style changes but the codebase should maintain consistent code conventions. I'll also add a style guide soon so this can be easier in the future. One option is upon destruction set the iframe container to the html contents of the editor inside the iframe. This would solve most of the event listener problems since all the listening dom nodes would get destroyed. The exception is the focus on the iframe container you have a test for but that could perhaps be changed to be attached to the iframe itself instead. |
Hey, no worries on enforcing styles! I agree on making those changes, so no problem :D Regarding moving the focus listener to the iframe, I'll check if that makes the tests pass and test it a little bit manually to see if that works. |
b2a8d8d
to
7303f75
Compare
Seems moving the |
Sorry for the delay. I was debating the best solution to the focus listener issue and think it might be that actually we can just pass in this.focus to the focus listener and thus that can just be passed into |
Since we're passing Perhaps I didn't understand correctly what you meant! So let me know if that's the case! |
I think the _.bind() call is unnecessary so if it's changed to dom(@iframeContainer).on('focus', this.focus) then later reference this.focus in the event removal step. |
We DO need the bind call, since the focus function is using |
Hmm okay forget dom.on attaches an anonymous function. What's the issue with IE? I'm not seeing any obvious errors.. |
You're right, it seems the editor is not losing focus on IE when the input is being focused. It doesn't seem to be related to this though, at least not in an obvious way. |
I'm not sure what you mean.. what input are you talking about? |
The one in the failing test https://travis-ci.org/quilljs/quill/jobs/37244733#L305 |
Sorry the latest release added a lot of changes and conflicts to this PR. There's no more focus listener so that issue has taken care of itself. The failing focus test might also have fixed itself as there were some focus issues that have been fixed in the latest release. If you can resolve the merge conflicts we can give this another try. |
Awesome! I'll resolve the conflicts and make this work On Friday, November 7, 2014, Jason Chen [email protected] wrote:
|
7303f75
to
049c176
Compare
049c176
to
d3fca14
Compare
@jhchen check it now, resolved the conflicts and made this work again |
destroy() method for Quill instances
Awesome thanks! |
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 thedestroy
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 nooff
method implemented in thedom
util, we need to have something for this. I have two ideas:off
by tracking the real listener and the wrapped listener in theWrapper
class, and callingremoveEventListener
with the same function thataddEventListener
was called with. For this to work we need to use the same instance of theWrapper
class, so things likedom(elem).on('focus', something); dom(elem).off('focus', something)
won't work.on
method to return a function that will remove the listener, instead of returning theWrapper
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 callingoff
. Here,off
will be called by you with the correct listener when you call the returning function fromon
. Also, I think there are no cases ofon
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!