One common workflow in highly interactive apps is asynchronously fetching external markup and then injecting it in a page. We used this technique in many places to dynamically update panel contents or preview fragments...
To account for it, different libraries offer different solutions like:
The goal of this story is to provide a custom globalEval that can be used throughout DXP as a replacement of the mentioned direct use cases.
- A runScriptsInElement method (or other name) is exported from frontend-js-web that allows to pass
- element The DOM element whose scripts should be executed
- The method is unit tested and documented
The current implementation of runScriptsInElement also accepts defaultFn and appendFn. While those can be useful, we don't have real usages for it in DXP so we can probably simplify the API design for now.