From 692cf5ad984a2607a4cee0b5cda56e8ccd7b18f3 Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Wed, 9 Feb 2022 18:16:16 +0800 Subject: [PATCH] feat: tree-shaking with bitwise operation --- packages/uni-shared/src/lifecycle.ts | 12 +++++++----- packages/uni-shared/src/vdom/encode.ts | 24 ++++++++++++++---------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/packages/uni-shared/src/lifecycle.ts b/packages/uni-shared/src/lifecycle.ts index 73b4c1cbc..289c382d9 100644 --- a/packages/uni-shared/src/lifecycle.ts +++ b/packages/uni-shared/src/lifecycle.ts @@ -76,8 +76,10 @@ export const UniLifecycleHooks = [ ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED, ] as const -export const MINI_PROGRAM_PAGE_RUNTIME_HOOKS = { - onPageScroll: 1, - onShareAppMessage: 1 << 1, - onShareTimeline: 1 << 2, -} as const +export const MINI_PROGRAM_PAGE_RUNTIME_HOOKS = /*#__PURE__*/ (() => { + return { + onPageScroll: 1, + onShareAppMessage: 1 << 1, + onShareTimeline: 1 << 2, + } as const +})() diff --git a/packages/uni-shared/src/vdom/encode.ts b/packages/uni-shared/src/vdom/encode.ts index 5c7d8bbd6..6e465a58f 100644 --- a/packages/uni-shared/src/vdom/encode.ts +++ b/packages/uni-shared/src/vdom/encode.ts @@ -1,8 +1,10 @@ -export const EventOptionFlags = { - capture: 1, - once: 1 << 1, - passive: 1 << 2, -} +export const EventOptionFlags = /*#__PURE__*/ (() => { + return { + capture: 1, + once: 1 << 1, + passive: 1 << 2, + } +})() export function encodeOptions(options?: AddEventListenerOptions) { let flag = 0 @@ -20,11 +22,13 @@ export function encodeOptions(options?: AddEventListenerOptions) { return flag } -export const EventModifierFlags = { - stop: 1, - prevent: 1 << 1, - self: 1 << 2, -} +export const EventModifierFlags = /*#__PURE__*/ (() => { + return { + stop: 1, + prevent: 1 << 1, + self: 1 << 2, + } +})() export function encodeModifier(modifiers: string[]) { let flag = 0 -- GitLab