Maybe there’s some way of doing this, not sure. But if you’ve got some function that returns HTML, and use it like [fn()] in your HTML, then use update(), that function will be called again, right? There’s no way of blocking that, as far as I know–which could do things like reset state and such.

Not even sure how you’d implement such a feature. Maybe pass an argument to the function telling it it’s updating or something? Or mark the code as only-run-once somehow? [:code run once]? Not sure… Could be useful for certain plug-ins though to avoid users of the plugin accidentally messing it up by using update().

  • wthit56@lemmy.worldOP
    link
    fedilink
    English
    arrow-up
    1
    ·
    2 months ago

    Right. Unless it’s the kind of plugin you have more than once in your HTML. Like some formatting thing or wrapper. Then you need to store every return from the function, and where it came from, and be able to cross reference the two–see what I mean?

    • VioneT@lemmy.worldM
      link
      fedilink
      English
      arrow-up
      1
      ·
      2 months ago

      Yup, a good example of it is the tap-plugin, different outputs but is remembered by the page.

      • wthit56@lemmy.worldOP
        link
        fedilink
        English
        arrow-up
        1
        ·
        2 months ago

        Ooh, an interesting plugin! It doesn’t work in the way I’m talking about at all though.

        The function would need to be able to generate some return value when called. But always return that same return value for that source call every time, so that when update() is called on an element that contains code that calls the function… it’s as if that code block was not re-evaluated at all.

        That tap plugin specifically does not use update() at all. And specially does generate new values when it’s interacted with. I’m not sure how it’s relevant. Maybe you could point me to the part you think is doing what I’m talking about?

        • VioneT@lemmy.worldM
          link
          fedilink
          English
          arrow-up
          2
          ·
          2 months ago

          Maybe the locker-plugin might be a better example. It essentially stores the ‘locked’ value, so when update() is used, it would only return the ‘locked’ value.

          • wthit56@lemmy.worldOP
            link
            fedilink
            English
            arrow-up
            2
            ·
            2 months ago

            Ah I see, that seems to work about as expected. Only annoyance is, the user of the plugin has to come up with a unique name and track those, make sure they don’t use the same name twice or whatever.

            This method would work, which is cool. I still feel like it would be a useful feature for the engine anyway. If only to save on processing those code blocks that the user only wants to “run once.”