feat(shared): support Map and Set in toDisplayString

close #1067, close #1100
This commit is contained in:
Evan You
2020-05-04 10:38:03 -04:00
parent ff97be15c3
commit 3c60d40827
3 changed files with 136 additions and 9 deletions

View File

@@ -11,6 +11,7 @@ export * from './domTagConfig'
export * from './domAttrConfig'
export * from './escapeHtml'
export * from './looseEqual'
export * from './toDisplayString'
export const EMPTY_OBJ: { readonly [key: string]: any } = __DEV__
? Object.freeze({})
@@ -112,15 +113,6 @@ export const capitalize = cacheStringFunction(
export const hasChanged = (value: any, oldValue: any): boolean =>
value !== oldValue && (value === value || oldValue === oldValue)
// For converting {{ interpolation }} values to displayed strings.
export const toDisplayString = (val: unknown): string => {
return val == null
? ''
: isArray(val) || (isPlainObject(val) && val.toString === objectToString)
? JSON.stringify(val, null, 2)
: String(val)
}
export const invokeArrayFns = (fns: Function[], arg?: any) => {
for (let i = 0; i < fns.length; i++) {
fns[i](arg)