fastn
fastn copied to clipboard
js files are getting called more than once
If I attach JS to a component, eg:
-- component icon:
caption url:
string prefix:
optional ftd.color color:
integer size: 24
-- ftd.container:
display: inline
width.fixed.px: $icon.size
height.fixed.px: $icon.size
color: $icon.color
js: $assets.files.helper.js
.. body omitted ..
-- end: ftd.container
-- end: icon
I have to do this for things to not crash if I am using it from different components:
(function() {
if (window.svg_helper_loaded) {
// TODO: why do we need this?
return;
}
window.svg_helper_loaded = true;
console.log("svg helper loaded");
let svg_cache = {};
... rest omitted ...
})();
If I do not use the if condition, the svg_cache line crashes.
Full code in https://github.com/fastn-community/svg-icons.