Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo-mod-jslibs-dist.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'alpinejs/packages/alpinejs/src/utils/once.js')
-rw-r--r--alpinejs/packages/alpinejs/src/utils/once.js14
1 files changed, 14 insertions, 0 deletions
diff --git a/alpinejs/packages/alpinejs/src/utils/once.js b/alpinejs/packages/alpinejs/src/utils/once.js
new file mode 100644
index 0000000..643ee6f
--- /dev/null
+++ b/alpinejs/packages/alpinejs/src/utils/once.js
@@ -0,0 +1,14 @@
+
+export function once(callback, fallback = () => {}) {
+ let called = false
+
+ return function () {
+ if (! called) {
+ called = true
+
+ callback.apply(this, arguments)
+ } else {
+ fallback.apply(this, arguments)
+ }
+ }
+}