From 62cffd67a4d14b27683a8b303ea08c9271eee1ab Mon Sep 17 00:00:00 2001 From: xiejiahe Date: Tue, 13 Apr 2021 17:52:51 +0800 Subject: [PATCH] style: using 'Array.prototype.forEach()' (#1826) --- packages/hooks/use-events/index.ts | 4 ++-- packages/popover/src/directive.ts | 2 +- packages/popper/src/use-popper/index.ts | 2 +- website/components/right-nav.vue | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/hooks/use-events/index.ts b/packages/hooks/use-events/index.ts index c9cc28cf4a..5ce36965ec 100644 --- a/packages/hooks/use-events/index.ts +++ b/packages/hooks/use-events/index.ts @@ -12,11 +12,11 @@ export default (el: Ref, events: Event[]) => { watch(el, val => { if (val) { - events.map(({ name, handler }) => { + events.forEach(({ name, handler }) => { on(el.value, name, handler) }) } else { - events.map(({ name, handler }) => { + events.forEach(({ name, handler }) => { off(el.value, name, handler) }) } diff --git a/packages/popover/src/directive.ts b/packages/popover/src/directive.ts index 7afabe1d06..83fc03842d 100644 --- a/packages/popover/src/directive.ts +++ b/packages/popover/src/directive.ts @@ -14,7 +14,7 @@ const attachEvents = (el: HTMLElement, binding: DirectiveBinding, vnode: VNode) popover.triggerRef = el el.setAttribute('tabindex', popover.tabindex) // because v-popover cannot modify the vnode itself due to it has already been - Object.entries(popover.events).map(([eventName, e]) => { + Object.entries(popover.events).forEach(([eventName, e]) => { on(el, eventName.toLowerCase().slice(2), e) }) } diff --git a/packages/popper/src/use-popper/index.ts b/packages/popper/src/use-popper/index.ts index aa03e75dff..07a7939744 100644 --- a/packages/popper/src/use-popper/index.ts +++ b/packages/popper/src/use-popper/index.ts @@ -248,7 +248,7 @@ export default function( } if (isArray(props.trigger)) { - Object.values(props.trigger).map(mapEvents) + Object.values(props.trigger).forEach(mapEvents) } else { mapEvents(props.trigger as TriggerType) } diff --git a/website/components/right-nav.vue b/website/components/right-nav.vue index 8893b7bd87..a75af805bf 100644 --- a/website/components/right-nav.vue +++ b/website/components/right-nav.vue @@ -56,7 +56,7 @@ export default defineComponent({ let mapValues = Array.from(map.values()).reverse() let mapKeys = Array.from(map.keys()).reverse() resizeObserver = new ResizeObserver(() => { - Array.from(h3).map(item => { + Array.from(h3).forEach(item => { const text = item.childNodes[1].textContent.trim() map.set(text, item.offsetTop) })