@koine/dom 1.0.87 → 1.0.90

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/listenResize.d.ts CHANGED
@@ -4,5 +4,5 @@ import { debounce } from "@koine/utils";
4
4
  *
5
5
  * @returns An automatic unbinding function to run to deregister the listener upon call
6
6
  */
7
- export declare function listenResize(...args: Parameters<typeof debounce>): () => void;
7
+ export declare function listenResize(...args: Parameters<typeof debounce>): (() => void) | undefined;
8
8
  export default listenResize;
package/listenResize.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import { debounce } from "@koine/utils";
2
2
  import { on } from "./on";
3
- import { off } from "./off";
4
3
  /**
5
4
  * Listen window resize event debouncing the given handler
6
5
  *
@@ -12,14 +11,7 @@ export function listenResize() {
12
11
  args[_i] = arguments[_i];
13
12
  }
14
13
  var handler = debounce.apply(void 0, args);
15
- on(window, "resize", handler);
16
- /**
17
- * Unbind the previously attached scroll handler
18
- */
19
- function unbinder() {
20
- handler.cancel();
21
- off(window, "resize", handler);
22
- }
14
+ var unbinder = on(window, "resize", handler);
23
15
  return unbinder;
24
16
  }
25
17
  export default listenResize;
package/listenScroll.d.ts CHANGED
@@ -4,5 +4,5 @@ import { debounce } from "@koine/utils";
4
4
  *
5
5
  * @returns An automatic unbinding function to run to deregister the listener upon call
6
6
  */
7
- export declare function listenScroll(...args: Parameters<typeof debounce>): () => void;
7
+ export declare function listenScroll(...args: Parameters<typeof debounce>): (() => void) | undefined;
8
8
  export default listenScroll;
package/listenScroll.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import { debounce } from "@koine/utils";
2
2
  import { on } from "./on";
3
- import { off } from "./off";
4
3
  /**
5
4
  * Listen window scroll event debouncing the given handler
6
5
  *
@@ -12,17 +11,10 @@ export function listenScroll() {
12
11
  args[_i] = arguments[_i];
13
12
  }
14
13
  var handler = debounce.apply(void 0, args);
15
- on(window, "scroll", handler, {
14
+ var unbinder = on(window, "scroll", handler, {
16
15
  capture: true,
17
16
  passive: true,
18
17
  });
19
- /**
20
- * Unbind the previously attached scroll handler
21
- */
22
- function unbinder() {
23
- handler.cancel();
24
- off(window, "scroll", handler);
25
- }
26
18
  return unbinder;
27
19
  }
28
20
  export default listenScroll;
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.listenResize = void 0;
4
4
  var utils_1 = require("@koine/utils");
5
5
  var on_1 = require("./on");
6
- var off_1 = require("./off");
7
6
  /**
8
7
  * Listen window resize event debouncing the given handler
9
8
  *
@@ -15,14 +14,7 @@ function listenResize() {
15
14
  args[_i] = arguments[_i];
16
15
  }
17
16
  var handler = utils_1.debounce.apply(void 0, args);
18
- (0, on_1.on)(window, "resize", handler);
19
- /**
20
- * Unbind the previously attached scroll handler
21
- */
22
- function unbinder() {
23
- handler.cancel();
24
- (0, off_1.off)(window, "resize", handler);
25
- }
17
+ var unbinder = (0, on_1.on)(window, "resize", handler);
26
18
  return unbinder;
27
19
  }
28
20
  exports.listenResize = listenResize;
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.listenScroll = void 0;
4
4
  var utils_1 = require("@koine/utils");
5
5
  var on_1 = require("./on");
6
- var off_1 = require("./off");
7
6
  /**
8
7
  * Listen window scroll event debouncing the given handler
9
8
  *
@@ -15,17 +14,10 @@ function listenScroll() {
15
14
  args[_i] = arguments[_i];
16
15
  }
17
16
  var handler = utils_1.debounce.apply(void 0, args);
18
- (0, on_1.on)(window, "scroll", handler, {
17
+ var unbinder = (0, on_1.on)(window, "scroll", handler, {
19
18
  capture: true,
20
19
  passive: true,
21
20
  });
22
- /**
23
- * Unbind the previously attached scroll handler
24
- */
25
- function unbinder() {
26
- handler.cancel();
27
- (0, off_1.off)(window, "scroll", handler);
28
- }
29
21
  return unbinder;
30
22
  }
31
23
  exports.listenScroll = listenScroll;
package/node/on.js CHANGED
@@ -1,10 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.on = void 0;
4
+ var off_1 = require("./off");
4
5
  /**
5
6
  * Shortcut for `addEventListener`
7
+ *
8
+ * @returns An automatic unbinding function to run to deregister the listener upon call
6
9
  */
7
- function on(el, type, handler, options) {
10
+ function on(el, type, handler /* EventListener | */ /* ((event: Event) => void) */, options) {
8
11
  if (options === void 0) { options = false; }
9
12
  if (process.env["NODE_ENV"] !== "production") {
10
13
  if (!el) {
@@ -12,8 +15,11 @@ function on(el, type, handler, options) {
12
15
  return;
13
16
  }
14
17
  }
15
- if (el)
18
+ if (el) {
16
19
  el.addEventListener(type, handler, options);
20
+ return function () { return (0, off_1.off)(el, type, handler); };
21
+ }
22
+ return function () { return void 0; };
17
23
  }
18
24
  exports.on = on;
19
25
  exports.default = on;
package/on.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  /**
2
2
  * Shortcut for `addEventListener`
3
+ *
4
+ * @returns An automatic unbinding function to run to deregister the listener upon call
3
5
  */
4
- export declare function on(el: Window | Document | HTMLElement | Element, type: string, handler: EventListener, options?: AddEventListenerOptions | boolean): void;
6
+ export declare function on<THandler extends (event: any) => void>(el: Window | Document | HTMLElement | Element, type: string, handler: THandler, options?: AddEventListenerOptions | boolean): (() => void) | undefined;
5
7
  export default on;
package/on.js CHANGED
@@ -1,7 +1,10 @@
1
+ import { off } from "./off";
1
2
  /**
2
3
  * Shortcut for `addEventListener`
4
+ *
5
+ * @returns An automatic unbinding function to run to deregister the listener upon call
3
6
  */
4
- export function on(el, type, handler, options) {
7
+ export function on(el, type, handler /* EventListener | */ /* ((event: Event) => void) */, options) {
5
8
  if (options === void 0) { options = false; }
6
9
  if (process.env["NODE_ENV"] !== "production") {
7
10
  if (!el) {
@@ -9,7 +12,10 @@ export function on(el, type, handler, options) {
9
12
  return;
10
13
  }
11
14
  }
12
- if (el)
15
+ if (el) {
13
16
  el.addEventListener(type, handler, options);
17
+ return function () { return off(el, type, handler); };
18
+ }
19
+ return function () { return void 0; };
14
20
  }
15
21
  export default on;
package/package.json CHANGED
@@ -4,13 +4,12 @@
4
4
  "main": "./node/index.js",
5
5
  "typings": "./index.d.ts",
6
6
  "dependencies": {
7
- "@koine/utils": "1.0.87",
7
+ "@koine/utils": "1.0.90",
8
8
  "ts-debounce": "^4.0.0",
9
- "date-fns-tz": "^1.3.7",
10
9
  "tslib": "^2.4.0"
11
10
  },
12
11
  "peerDependencies": {},
13
- "version": "1.0.87",
12
+ "version": "1.0.90",
14
13
  "module": "./index.js",
15
14
  "types": "./index.d.ts"
16
15
  }