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 getter-return */
|
||||
/* eslint-disable import/no-mutable-exports */
|
||||
import { noop, isServer } from '.';
|
||||
import { isServer } from '.';
|
||||
|
||||
type EventHanlder = (event?: Event) => void;
|
||||
|
||||
@ -16,18 +16,29 @@ if (!isServer) {
|
||||
supportsPassive = true;
|
||||
}
|
||||
});
|
||||
window.addEventListener('test-passive', noop, opts);
|
||||
window.addEventListener('test-passive', null as any, opts);
|
||||
} 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) {
|
||||
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) {
|
||||
!isServer && target.removeEventListener(event, handler);
|
||||
if (!isServer) {
|
||||
target.removeEventListener(event, handler);
|
||||
}
|
||||
}
|
||||
|
||||
export function stop(event: Event) {
|
||||
|
@ -19,10 +19,10 @@ function fallback(fn: FrameRequestCallback): number {
|
||||
const root = <Window>(isServer ? global : window);
|
||||
|
||||
/* istanbul ignore next */
|
||||
const iRaf = root.requestAnimationFrame || root.webkitRequestAnimationFrame || fallback;
|
||||
const iRaf = root.requestAnimationFrame || fallback;
|
||||
|
||||
/* istanbul ignore next */
|
||||
const iCancel = root.cancelAnimationFrame || root.webkitCancelAnimationFrame || root.clearTimeout;
|
||||
const iCancel = root.cancelAnimationFrame || root.clearTimeout;
|
||||
|
||||
export function raf(fn: FrameRequestCallback): number {
|
||||
return iRaf.call(root, fn);
|
||||
|
@ -85,11 +85,9 @@ function defaultProps(props: any) {
|
||||
|
||||
function install(this: ComponentOptions<Vue>, Vue: VueConstructor) {
|
||||
const { name } = this;
|
||||
if (name) {
|
||||
Vue.component(name, this);
|
||||
Vue.component(name as string, this);
|
||||
Vue.component(camelize(`-${name}`), this);
|
||||
}
|
||||
}
|
||||
|
||||
// unify slots & scopedSlots
|
||||
export function unifySlots(context: RenderContext) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user