Seems like plugins almost always have some sort of setup to go through when they’re first used. Really, they’d want to just run that code when first imported. But presumably there is no way creators can do that, currently. As it’s such a common use-case, having something like this built-in for plugins would be useful, I think.

  • BluePower
    link
    fedilink
    English
    arrow-up
    1
    ·
    4 months ago

    A simple, practical approach (for now) would be to put the function inside the $output() like this:

    $output() =>
      if (!window.__onloadExecuted) {
        onload(); window.__onloadExecuted = true;
      }
      // ...
    
    // The homemade onload function
    onload() =>
      // ...
    

    However, it only works when at least one instance of the plugin is being executed in the generator code.