Created on 4 October 2023, 9 months ago
Updated 17 October 2023, 8 months ago

Support window like jQuery does.

I ended up refactoring

var init = $(window, context).once("tag");
if (init.length) {
 // Ensures function runs once *globally
}

to

const init = once('tag', 'html');
if (init.length) {
 // Ensures function runs once *globally
}

And I have to use html, instead of window. In my opinion window is not in the DOM and it is much performant.

I know, once('tag', 'html').forEach() also does the same but we have a word in Turkish which is Everyone eats yoghurt differently

✨ Feature request
Status

Closed: works as designed

Component

Code

Created by

πŸ‡ΉπŸ‡·Turkey emircanerkul Turkey

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @emircanerkul
  • Status changed to Closed: works as designed 8 months ago
  • πŸ‡«πŸ‡·France nod_ Lille

    Thanks for the suggestion, the once feature is made to work with DOM nodes so that we can expose the data attributes to the outside. Like you said, window is not the DOM so it can't work with once.

    The performance point is not actually an issue. When we rewrote the once feature we did extensive preformance testing and bottleneck will just not be in the once calls. The DOM is much faster these days. Have a look at the benchmarks to see just how fast that is: https://www.measurethat.net/Benchmarks/Show/8844/1/drupal-once-variables...

Production build 0.69.0 2024