snail.view 1.0.23 → 1.0.24

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.
@@ -486,9 +486,10 @@ interface IObserver {
486
486
  * @param target 监听元素
487
487
  * @param name 事件名称
488
488
  * @param fn 事件处理方法
489
+ * @param useCapture 是否使用捕获模式
489
490
  * @returns 作用域,可销毁监听
490
491
  */
491
- onEvent(target: Element | Window, name: string, fn: (...args: any[]) => void): IScope;
492
+ onEvent(target: Element | Window, name: string, fn: (...args: any[]) => void, useCapture?: boolean): IScope;
492
493
  /**
493
494
  * 监听元素尺寸变化
494
495
  * - scope销毁时自动移除监听
@@ -252,13 +252,13 @@ function configLink(options) {
252
252
 
253
253
  function useObserver() {
254
254
  const scopes = useScopes();
255
- function onEvent(target, name, fn) {
255
+ function onEvent(target, name, fn, useCapture) {
256
256
  checkScope(manager, "onEvent: observer destroyed.");
257
257
  throwIfFalse(target instanceof Element || target === window, "onEvent: target must be a Element or Window");
258
258
  mustString(name, "onEvent: name");
259
259
  mustFunction(fn, "onEvent: fn");
260
- target.addEventListener(name, fn);
261
- return scopes.get().onDestroy(() => target.removeEventListener(name, fn));
260
+ target.addEventListener(name, fn, useCapture);
261
+ return scopes.get().onDestroy(() => target.removeEventListener(name, fn, useCapture));
262
262
  }
263
263
  function onSize(el, fn) {
264
264
  checkScope(manager, "onSize: observer destroyed.");
@@ -256,13 +256,13 @@
256
256
 
257
257
  function useObserver() {
258
258
  const scopes = snail_core.useScopes();
259
- function onEvent(target, name, fn) {
259
+ function onEvent(target, name, fn, useCapture) {
260
260
  snail_core.checkScope(manager, "onEvent: observer destroyed.");
261
261
  snail_core.throwIfFalse(target instanceof Element || target === window, "onEvent: target must be a Element or Window");
262
262
  snail_core.mustString(name, "onEvent: name");
263
263
  snail_core.mustFunction(fn, "onEvent: fn");
264
- target.addEventListener(name, fn);
265
- return scopes.get().onDestroy(() => target.removeEventListener(name, fn));
264
+ target.addEventListener(name, fn, useCapture);
265
+ return scopes.get().onDestroy(() => target.removeEventListener(name, fn, useCapture));
266
266
  }
267
267
  function onSize(el, fn) {
268
268
  snail_core.checkScope(manager, "onSize: observer destroyed.");
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "对视图界面做的一些封装。如样式计算助手方法,常用样式less混入、变量等;dom相关助手类",
4
4
  "author": "snail_dev@163.com",
5
5
  "license": "MIT",
6
- "version": "1.0.23",
6
+ "version": "1.0.24",
7
7
  "type": "module",
8
8
  "main": "dist/snail.view.js",
9
9
  "module": "dist/snail.view.js",