Generalize js_handler
with Auto-Return-Value-Intercept (ARVI)
#4759
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.
This PR should end the saga of PR #4689, PR #4618, while addressing 5 issue / discussions / feature request (#3762, #4611, #4606, #4577, and #4589) as stated in #4618 (comment)
Background
The crux of the issue is, we want to be able to return custom values which are only possible to be extracted via JavaScript and/or too deep in nested property which
args
does not handle. Stuff gets pretty complex and case-by-case, so read up those 7 referenced items above!Established Requirements
We debated a long time over the API design, and we needed the following requirements:
js_transform = "(e) => e.offsetY"
was eliminated"(e) => e.offsetY"
js_handler = "(e) => {defaultHandler(e.offsetY)}"
was eliminatedargs
", as well as all other above options, were eliminatedThis PR illustrates the idea at #4689 (comment) to comply with all of the aforementioned requirements.
"(e) => e.offsetY"
js_handler = "(e) => e.offsetY"
Logic behind this PR
The keyword is ARVI, which stands for Auto-Return-Value-Intercept. It means we intercept the
js_handler
's return value, if and only if Python-sidehandler
is attached.As a recap from #4689 (comment):
.on('blah', handler=python_handler, js_handler='(e) => e.event.button')
handler
andjs_handler
, we now do care about the return value, and if there is a return value, we pass todefaultHandler
right away..on('blah', js_handler='(e) => e.event.button')
js_handler
doesn't care about return value..on('blah', handler=python_handler)
Notable implementation details
args
andjs_handler
remain mutally exclusive.if (event.js_handler) {
changed safely toif (!event.handler) {
if handler or js_handler:
on Python-sideRemaining to-do