Skip to content

Commit 5669411

Browse files
committed
add hooks for devtools
1 parent 6855f64 commit 5669411

File tree

7 files changed

+33
-2
lines changed

7 files changed

+33
-2
lines changed

src/batcher.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ function flushBatcherQueue () {
3434
runBatcherQueue(queue)
3535
internalQueueDepleted = true
3636
runBatcherQueue(userQueue)
37+
// dev tool hook
38+
/* istanbul ignore if */
39+
if (process.env.NODE_ENV !== 'production') {
40+
if (_.inBrowser && window.__VUE_DEVTOOLS_GLOBAL_HOOK__) {
41+
window.__VUE_DEVTOOLS_GLOBAL_HOOK__.emit('flush')
42+
}
43+
}
3744
resetBatcherState()
3845
}
3946

src/directive.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ function Directive (descriptor, vm, el, host, scope, frag) {
4646
this._host = host
4747
this._scope = scope
4848
this._frag = frag
49+
// store directives on node in dev mode
50+
if (process.env.NODE_ENV !== 'production' && this.el) {
51+
this.el._vue_directives = this.el._vue_directives || []
52+
this.el._vue_directives.push(this)
53+
}
4954
}
5055

5156
/**
@@ -305,6 +310,9 @@ Directive.prototype._teardown = function () {
305310
unwatchFns[i]()
306311
}
307312
}
313+
if (process.env.NODE_ENV !== 'production' && this.el) {
314+
this.el._vue_directives.$remove(this)
315+
}
308316
this.vm = this.el = this._watcher = this._listeners = null
309317
}
310318
}

src/directives/internal/component.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ module.exports = {
108108
resolveComponent: function (id, cb) {
109109
var self = this
110110
this.pendingComponentCb = _.cancellable(function (Component) {
111+
self.ComponentName = id
111112
self.Component = Component
112113
cb()
113114
})
@@ -171,6 +172,7 @@ module.exports = {
171172
if (this.Component) {
172173
// default options
173174
var options = {
175+
name: this.ComponentName,
174176
el: templateParser.clone(this.el),
175177
template: this.inlineTemplate,
176178
// make sure to add the child with correct parent
@@ -294,6 +296,11 @@ module.exports = {
294296
transition: function (target, cb) {
295297
var self = this
296298
var current = this.childVM
299+
// for devtool inspection
300+
if (process.env.NODE_ENV !== 'production') {
301+
if (current) current._inactive = true
302+
target._inactive = false
303+
}
297304
this.childVM = target
298305
switch (self.params.transitionMode) {
299306
case 'in-out':

src/instance/init.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
var mergeOptions = require('../util').mergeOptions
2+
var uid = 0
23

34
/**
45
* The main init sequence. This is called for every
@@ -26,6 +27,9 @@ exports._init = function (options) {
2627
this._watchers = [] // all watchers as an array
2728
this._directives = [] // all directives
2829

30+
// a uid
31+
this._uid = uid++
32+
2933
// a flag to avoid this being observed
3034
this._isVue = true
3135

src/util/options.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,6 @@ function guardComponents (options) {
232232
}
233233
def = components[key]
234234
if (_.isPlainObject(def)) {
235-
def.name = def.name || key
236235
components[key] = _.Vue.extend(def)
237236
}
238237
}

src/vue.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,10 @@ extend(p, require('./api/lifecycle'))
8787

8888
Vue.version = '1.0.0-rc.2'
8989
module.exports = _.Vue = Vue
90+
91+
/* istanbul ignore if */
92+
if (process.env.NODE_ENV !== 'production') {
93+
if (_.inBrowser && window.__VUE_DEVTOOLS_GLOBAL_HOOK__) {
94+
window.__VUE_DEVTOOLS_GLOBAL_HOOK__.emit('init', Vue)
95+
}
96+
}

test/unit/specs/util/options_spec.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ describe('Util - Option merging', function () {
150150
}
151151
})
152152
expect(typeof res.components.test).toBe('function')
153-
expect(res.components.test.options.name).toBe('test')
154153
expect(res.components.test.super).toBe(Vue)
155154
})
156155

0 commit comments

Comments
 (0)