refactor(reactivity): refactor iteration key trigger logic + use more robust Map/Set check

This commit is contained in:
Evan You
2020-09-14 11:26:34 -04:00
parent cf1b6c666f
commit 0124eacc91
5 changed files with 48 additions and 28 deletions

View File

@@ -1,4 +1,4 @@
import { isArray, isObject, isPlainObject } from './index'
import { isArray, isMap, isObject, isPlainObject, isSet } from './index'
/**
* For converting {{ interpolation }} values to displayed strings.
@@ -13,14 +13,14 @@ export const toDisplayString = (val: unknown): string => {
}
const replacer = (_key: string, val: any) => {
if (val instanceof Map) {
if (isMap(val)) {
return {
[`Map(${val.size})`]: [...val.entries()].reduce((entries, [key, val]) => {
;(entries as any)[`${key} =>`] = val
return entries
}, {})
}
} else if (val instanceof Set) {
} else if (isSet(val)) {
return {
[`Set(${val.size})`]: [...val.values()]
}