@lekoala/date-picker 0.5.3 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/session.js ADDED
@@ -0,0 +1,23 @@
1
+ /**
2
+ * One lifetime: a picker connection, a calendar connection or a field
3
+ * controller. The returned controller is the token an operation captures
4
+ * before it suspends.
5
+ * @returns {AbortController}
6
+ */
7
+ export function createSession() {
8
+ return new AbortController();
9
+ }
10
+
11
+ /**
12
+ * Protect a callback with the signal captured now. The caller keeps the
13
+ * scheduling choice (`queueMicrotask` vs `setTimeout`), because focus behavior
14
+ * in Chromium depends on it.
15
+ * @param {AbortSignal} signal
16
+ * @param {() => void} callback
17
+ * @returns {() => void}
18
+ */
19
+ export function guard(signal, callback) {
20
+ return () => {
21
+ if (!signal.aborted) callback();
22
+ };
23
+ }