Skip to content

Instantly share code, notes, and snippets.

@vendethiel
Last active March 31, 2022 12:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vendethiel/cb188183e631ba40dfc085081b7e53a8 to your computer and use it in GitHub Desktop.
Save vendethiel/cb188183e631ba40dfc085081b7e53a8 to your computer and use it in GitHub Desktop.
Once
const once = (function () {
const fns = [];
let i = 0;
return function (fn) {
const cur = i++;
fns[cur] = fn;
return function () {
if (fns[cur]) {
fns[cur].apply(null, arguments);
fns[cur] = null;
}
}
}
})();
const query = once(sendRequest);
function MyComponent() {
query();
}
once = let fns = [], i = 0
->
cur = i++
fns[cur] = it
->
fns[cur]? ...
fns[cur] = void
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment