Hi,
Has anyone tried dynamic import of es7 functions ?
Following ‘non returning function’ works for me -
// CalledFn
(async () => {
// e.g. const { Mongo } = await import('meteor/mongo');
const main = () => {
console.log('Called);
};
main()
})();
---
// Calling FN
(async () => {
import('./calledFN');
// or - if you need things to wait - await import('./calledFN');
})();
Now to get a return from the module we need to change things a bit:
// CalledFn
const CalledFN = (async () => {
// e.g. const { Mongo } = await import('meteor/mongo');
const main = () => {
return 'awesome';
};
return main();
})();
export default CalledFN;
---
// Calling FN
(async () => {
// Below works, but of course does not return anything
import('./calledFN');
// Below works as well
import('../calledFN').then((pValue) => {
pValue.default.then((p2) => {
console.log(p2);
});
});
// Then if you introduce await - it blocks and fails
const test = await (await import('../calledFN')).default;
})();
The await is blocking something and I seem to be missing something? Cheers for the assist guys .