Fix for Issue #6 Event handler removal fails. #8
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
#6
Attaching an event handler with JavaScript.JQuery.on returns an IO () that is supposed to remove the handler. JavaScript.JQuery.on calls JavaScript.JQuery.Internal.jq_on, which wraps the provided callback in a closure using h$jquery_makeListener. But the original callback is what is passed to JavaScript.JQuery.off. In order for $().off to remove the handler, the arguments must be identical.
I have modified by .on and .one and jq_on so that the closure created by j$jquery_makeListener is returned by jq_on. This fixes the removal. See the program https://github.com/cliffordbeshers/vdom-event/blob/master/TestDetach.hs as proof. Click the left button to see a message appear, the right button to remove the handler from the left. Before merging this branch, the left button will continue to append messages to the DOM.
This code needs review.
a) I modified the type signatures of jq_on and on. They compile, but I am not sure if they are the tightest they could be.
b) After the event handler is turned of, the cb callback value is released. Should this now be the value returned by jq_on, called cb' in the code? I left it as it was originally, but fear this introduces a leak.