Skip to content
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

Why are there separate async methods for shortcodes, filters? #1382

Closed
luwes opened this issue Aug 30, 2020 · 2 comments
Closed

Why are there separate async methods for shortcodes, filters? #1382

luwes opened this issue Aug 30, 2020 · 2 comments

Comments

@luwes
Copy link

luwes commented Aug 30, 2020

Just wondering if there is a reason this has to be explicit? e.g. addNunjucksAsyncFilter()

Wouldn't it be possible to derive this from the async keyword that is defined before the callback?
Seems a nicer devex, less API's.

For example addNunjucksFilter('myFilter', async () => {})

See here for detecting an async function, a lot of test runners use this technique; AVA, Tape, etc
https://stackoverflow.com/a/38510353/268820

@dz4k
Copy link

dz4k commented Dec 15, 2020

One reason I can think of: not all async functions are async functions, one could also implement asynchrony with just new Promise() and .then().

Secondly, the SO link you included mentions that some transpilers might transform async functions to normal ones. I'm not sure how many people transpile their .eleventy.js but I'm sure there are some.

@zachleat
Copy link
Member

Took your suggestion!

Read more here: https://www.11ty.dev/docs/filters/#asynchronous-universal-filters

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants