Skip to content

Commit 984ce87

Browse files
author
Guillaume Chau
committed
Fix vuejs#528
1 parent fb17cbe commit 984ce87

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

shells/dev/target/NativeTypes.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@ import CompDef from './Other.vue'
2323
export default {
2424
components: {
2525
TestComponent: {
26-
data: () => ({ foo: '42' }),
2726
props: { bar: { default: 'hey' }},
27+
data: () => ({ foo: '42' }),
28+
computed: {
29+
parentComp () { return this.$parent }
30+
},
2831
render: h => h('div', '<TestComponent />')
2932
}
3033
},

src/util.js

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,27 @@ export const SPECIAL_TOKENS = {
5858
'NaN': NAN
5959
}
6060

61+
class EncodeCache {
62+
constructor () {
63+
this.map = new Map()
64+
}
65+
66+
cache (data, factory) {
67+
const cached = this.map.get(data)
68+
if (cached) {
69+
return cached
70+
} else {
71+
const result = factory(data)
72+
this.map.set(data, result)
73+
return result
74+
}
75+
}
76+
}
77+
78+
let encodeCache
79+
6180
export function stringify (data) {
81+
encodeCache = new EncodeCache()
6282
return CircularJSON.stringify(data, replacer)
6383
}
6484

@@ -78,13 +98,13 @@ function replacer (key) {
7898
} else if (val instanceof Date) {
7999
return `[native Date ${val.toString()}]`
80100
} else if (isVuexStore(val)) {
81-
return getCustomStoreDetails(val)
101+
return encodeCache.cache(val, () => getCustomStoreDetails(val))
82102
} else if (isVueRouter(val)) {
83-
return getCustomRouterDetails(val)
103+
return encodeCache.cache(val, () => getCustomRouterDetails(val))
84104
} else if (val && val._isVue) {
85-
return getCustomInstanceDetails(val)
105+
return encodeCache.cache(val, () => getCustomInstanceDetails(val))
86106
} else if (isComponentDefinition(val)) {
87-
return getCustomComponentDefinitionDetails(val)
107+
return encodeCache.cache(val, () => getCustomComponentDefinitionDetails(val))
88108
} else {
89109
const type = typeof val
90110
if (type === 'function') {

0 commit comments

Comments
 (0)