vben
2023-04-05 8e5a6b7ce547ba8edb1d767bb4d820f3b66ff95a
src/hooks/core/useAttrs.ts
@@ -1,14 +1,16 @@
import { getCurrentInstance, reactive, shallowRef, watchEffect } from 'vue';
import type { Ref } from 'vue';
interface Params {
  excludeListeners?: boolean;
  excludeKeys?: string[];
  excludeDefaultKeys?: boolean;
}
const DEFAULT_EXCLUDE_KEYS = ['class', 'style'];
const LISTENER_PREFIX = /^on[A-Z]/;
export function entries<T>(obj: Hash<T>): [string, T][] {
export function entries<T>(obj: Recordable<T>): [string, T][] {
  return Object.keys(obj).map((key: string) => [key, obj[key]]);
}
@@ -16,9 +18,9 @@
  const instance = getCurrentInstance();
  if (!instance) return {};
  const { excludeListeners = false, excludeKeys = [] } = params;
  const { excludeListeners = false, excludeKeys = [], excludeDefaultKeys = true } = params;
  const attrs = shallowRef({});
  const allExcludeKeys = excludeKeys.concat(DEFAULT_EXCLUDE_KEYS);
  const allExcludeKeys = excludeKeys.concat(excludeDefaultKeys ? DEFAULT_EXCLUDE_KEYS : []);
  // Since attrs are not reactive, make it reactive instead of doing in `onUpdated` hook for better performance
  instance.attrs = reactive(instance.attrs);
@@ -30,7 +32,7 @@
      }
      return acm;
    }, {} as Hash<any>);
    }, {} as Recordable);
    attrs.value = res;
  });