Skip to content

change enumeration method of component's computed props #274

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions shells/dev/target/Other.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,19 @@
</template>

<script>
// this computed property should be visible
// even if component has no 'computed' defined
const computedPropMixin = {
computed: {
computedPropFromMixin() {
return null
}
}
}

export default {
props: ['id'],
mixins: [ computedPropMixin ],
data () {
let a = { c: function () {} }
a.a = a
Expand Down
18 changes: 14 additions & 4 deletions src/backend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -429,23 +429,33 @@ function processState (instance) {
*/

function processComputed (instance) {
return Object.keys(instance.$options.computed || {}).map(key => {
const computed = []
// use for...in here because if 'computed' is not defined
// on component, computed properties will be placed in prototype
// and Object.keys does not include
// properties from object's prototype
for (const key in (instance.$options.computed || {})) {
// use try ... catch here because some computed properties may
// throw error during its evaluation
let computedProp = null
try {
return {
computedProp = {
type: 'computed',
key,
value: instance[key]
}
} catch (e) {
return {
computedProp = {
type: 'computed',
key,
value: '(error during evaluation)'
}
}
})

computed.push(computedProp)
}

return computed
}

/**
Expand Down