mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
[improvement] optimize utils (#3104)
This commit is contained in:
parent
1a7daecdbc
commit
d3054fd4b0
@ -1,7 +1,7 @@
|
|||||||
/* eslint-disable no-empty */
|
/* eslint-disable no-empty */
|
||||||
/* eslint-disable getter-return */
|
/* eslint-disable getter-return */
|
||||||
/* eslint-disable import/no-mutable-exports */
|
/* eslint-disable import/no-mutable-exports */
|
||||||
import { noop, isServer } from '.';
|
import { isServer } from '.';
|
||||||
|
|
||||||
type EventHanlder = (event?: Event) => void;
|
type EventHanlder = (event?: Event) => void;
|
||||||
|
|
||||||
@ -16,18 +16,29 @@ if (!isServer) {
|
|||||||
supportsPassive = true;
|
supportsPassive = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
window.addEventListener('test-passive', noop, opts);
|
window.addEventListener('test-passive', null as any, opts);
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function on(target: HTMLElement, event: string, handler: EventHanlder, passive = false) {
|
export function on(
|
||||||
|
target: HTMLElement,
|
||||||
|
event: string,
|
||||||
|
handler: EventHanlder,
|
||||||
|
passive = false
|
||||||
|
) {
|
||||||
if (!isServer) {
|
if (!isServer) {
|
||||||
target.addEventListener(event, handler, supportsPassive ? { capture: false, passive } : false);
|
target.addEventListener(
|
||||||
|
event,
|
||||||
|
handler,
|
||||||
|
supportsPassive ? { capture: false, passive } : false
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function off(target: HTMLElement, event: string, handler: EventHanlder) {
|
export function off(target: HTMLElement, event: string, handler: EventHanlder) {
|
||||||
!isServer && target.removeEventListener(event, handler);
|
if (!isServer) {
|
||||||
|
target.removeEventListener(event, handler);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function stop(event: Event) {
|
export function stop(event: Event) {
|
||||||
|
@ -19,10 +19,10 @@ function fallback(fn: FrameRequestCallback): number {
|
|||||||
const root = <Window>(isServer ? global : window);
|
const root = <Window>(isServer ? global : window);
|
||||||
|
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
const iRaf = root.requestAnimationFrame || root.webkitRequestAnimationFrame || fallback;
|
const iRaf = root.requestAnimationFrame || fallback;
|
||||||
|
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
const iCancel = root.cancelAnimationFrame || root.webkitCancelAnimationFrame || root.clearTimeout;
|
const iCancel = root.cancelAnimationFrame || root.clearTimeout;
|
||||||
|
|
||||||
export function raf(fn: FrameRequestCallback): number {
|
export function raf(fn: FrameRequestCallback): number {
|
||||||
return iRaf.call(root, fn);
|
return iRaf.call(root, fn);
|
||||||
|
@ -85,10 +85,8 @@ function defaultProps(props: any) {
|
|||||||
|
|
||||||
function install(this: ComponentOptions<Vue>, Vue: VueConstructor) {
|
function install(this: ComponentOptions<Vue>, Vue: VueConstructor) {
|
||||||
const { name } = this;
|
const { name } = this;
|
||||||
if (name) {
|
Vue.component(name as string, this);
|
||||||
Vue.component(name, this);
|
|
||||||
Vue.component(camelize(`-${name}`), this);
|
Vue.component(camelize(`-${name}`), this);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// unify slots & scopedSlots
|
// unify slots & scopedSlots
|
||||||
|
Loading…
x
Reference in New Issue
Block a user