-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Add support for ES module (import
/export
syntax) callbacks
#12812
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
Conversation
Codecov Report
@@ Coverage Diff @@
## branch-3.2 #12812 +/- ##
===========================================
Coverage 92.43% 92.43%
===========================================
Files 315 315
Lines 20054 20070 +16
===========================================
+ Hits 18537 18552 +15
- Misses 1517 1518 +1 |
I am pretty 👎 on a new thing and especially on that thing being called |
3938cc0
to
a6e1bc3
Compare
Given that there's this many
then I will have to figure out how to not duplicate all of the above. In fact I would like the module variant to become the default and phase out the existing variant. I will probably just detect |
Another idea/option would be to provide the ability to declare imports not within CustomJS snippets but to apply them to the entire curdoc, i.e. a lot like what I'm doing by embedding CDN URLs in the template. I don't wanna have to import d3 in every snippet of CustomJS I write for an application, I wanna have access to it in every single one. Maybe having both options would be ideal so you could limit the scope of certain imports if you want? |
a6e1bc3
to
1b0e0de
Compare
1b0e0de
to
740080f
Compare
CustomESM
callbacksimport
/export
syntax) callbacks
We could set up an |
b678e51
to
013930a
Compare
013930a
to
87d4640
Compare
87d4640
to
ddabf65
Compare
This is ready for review. For now I added support only to |
The order of arguments is up to debate. Probably a better order would be export default function({source, slider}, _, {geometry: {sx, sy}}) {
...
} |
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.
Couple of comments but LGTM
return true | ||
default: | ||
return false | ||
} |
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.
incredible
02faa58
to
d5b589c
Compare
…#12812) * Add support for CustomESM callbacks * Allow callbacks to be asynchronous * Merge ESM support into CustomJS * Add support for CustomJS.from_file() * Add release notes * Make sure unzip([]) doesn't fail * Add AsyncGeneratorFunction to core/types * Allow isFunction() to detect generator functions * Update CustomJS' unit tests * Add unit tests for `CustomJS.from_file()`
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Add support for ES modules (static
import
andexport
syntax) to custom JS callbacks. The main reason for this is to allow external module imports. The example is adapted from #12808.CustomJS.code
can be two things now:code
orargs
change, and can return aPromise
.export default
syntax, e.g.:The exported default function can be a
function
,async function
, arrow function() => ...
, async arrow functionasync () => ...
, or even a generator function. Arguments to the function are fixed and independent ofCustomJS.args
. One can take advantage of object decomposition to reveal the passed-in arguments, e.g.:Additionally there's
CustomJS.from_file(path, **args)
to allow creating JS callbacks from source files (supported file extensions are*.js
and*.mjs
).