fastn icon indicating copy to clipboard operation
fastn copied to clipboard

js files are getting called more than once

Open amitu opened this issue 2 years ago • 0 comments

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.

amitu avatar Dec 04 '23 15:12 amitu