Skip to content

Commit

Permalink
Fix vuejs#528
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Chau committed Jan 19, 2018
1 parent fb17cbe commit 984ce87
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
5 changes: 4 additions & 1 deletion shells/dev/target/NativeTypes.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ import CompDef from './Other.vue'
export default {
components: {
TestComponent: {
data: () => ({ foo: '42' }),
props: { bar: { default: 'hey' }},
data: () => ({ foo: '42' }),
computed: {
parentComp () { return this.$parent }
},
render: h => h('div', '<TestComponent />')
}
},
Expand Down
28 changes: 24 additions & 4 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,27 @@ export const SPECIAL_TOKENS = {
'NaN': NAN
}

class EncodeCache {
constructor () {
this.map = new Map()
}

cache (data, factory) {
const cached = this.map.get(data)
if (cached) {
return cached
} else {
const result = factory(data)
this.map.set(data, result)
return result
}
}
}

let encodeCache

export function stringify (data) {
encodeCache = new EncodeCache()
return CircularJSON.stringify(data, replacer)
}

Expand All @@ -78,13 +98,13 @@ function replacer (key) {
} else if (val instanceof Date) {
return `[native Date ${val.toString()}]`
} else if (isVuexStore(val)) {
return getCustomStoreDetails(val)
return encodeCache.cache(val, () => getCustomStoreDetails(val))
} else if (isVueRouter(val)) {
return getCustomRouterDetails(val)
return encodeCache.cache(val, () => getCustomRouterDetails(val))
} else if (val && val._isVue) {
return getCustomInstanceDetails(val)
return encodeCache.cache(val, () => getCustomInstanceDetails(val))
} else if (isComponentDefinition(val)) {
return getCustomComponentDefinitionDetails(val)
return encodeCache.cache(val, () => getCustomComponentDefinitionDetails(val))
} else {
const type = typeof val
if (type === 'function') {
Expand Down

0 comments on commit 984ce87

Please sign in to comment.