Skip to content

Commit

Permalink
feat: show injected properties (vuejs#659)
Browse files Browse the repository at this point in the history
* show injected properties

* test: injected props
  • Loading branch information
hosmelq authored and Akryum committed Jul 26, 2018
1 parent a5095c6 commit 5e6c310
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
12 changes: 12 additions & 0 deletions cypress/integration/components-tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,16 @@ suite('components tab', () => {
cy.get('.instance .self .attr-title').contains('key')
cy.get('.instance .self .attr-value').contains('1')
})

it('should display injected props', () => {
cy.get('.left .search input').clear().type('Mine')
cy.get('.instance').eq(1).click()
cy.get('.right .data-wrapper').then(el => {
expect(el.text()).to.contain('injected')
expect(el.text()).to.contain('answer:42')
expect(el.text()).to.contain('foo:"bar"')
expect(el.text()).to.contain('noop:ƒ noop(a, b, c)')
})
cy.get('.left .search input').clear()
})
})
10 changes: 8 additions & 2 deletions shells/dev/target/Other.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div>
Other {{ id }}
<mine></mine>
<mine/>
</div>
</template>

Expand All @@ -18,8 +18,13 @@ const computedPropMixin = {
export default {
name: 'other-with-mine',
props: ['id'],
mixins: [computedPropMixin],
provide: {
foo: 'bar',
noop: (a, b, c) => {},
answer: 42
},
props: ['id'],
data () {
const a = { c: function () {} }
a.a = a
Expand All @@ -32,6 +37,7 @@ export default {
},
components: {
mine: {
inject: ['foo', 'noop', 'answer'],
render: h => h('div', { class: 'mine' }, 'mine'),
data () {
return {
Expand Down
24 changes: 24 additions & 0 deletions src/backend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ function getInstanceState (instance) {
return processProps(instance).concat(
processState(instance),
processComputed(instance),
processInjected(instance),
processRouteContext(instance),
processVuexGetters(instance),
processFirebaseBindings(instance),
Expand Down Expand Up @@ -563,6 +564,29 @@ function processComputed (instance) {
return computed
}

/**
* Process Vuex getters.
*
* @param {Vue} instance
* @return {Array}
*/

function processInjected (instance) {
const injected = instance.$options.inject

if (injected) {
return Object.keys(injected).map(key => {
return {
key,
type: 'injected',
value: instance[key]
}
})
} else {
return []
}
}

/**
* Process possible vue-router $route context
*
Expand Down

0 comments on commit 5e6c310

Please sign in to comment.