@@ -189,6 +189,11 @@ var config = {
189189 */
190190 silent : false ,
191191
192+ /**
193+ * Whether to enable devtools
194+ */
195+ devtools : process . env . NODE_ENV !== 'production' ,
196+
192197 /**
193198 * Error handler for watcher errors
194199 */
@@ -199,6 +204,11 @@ var config = {
199204 */
200205 ignoredElements : null ,
201206
207+ /**
208+ * Custom user key aliases for v-on
209+ */
210+ keyCodes : Object . create ( null ) ,
211+
202212 /**
203213 * Check if a tag is reserved so that it cannot be registered as a
204214 * component. This is platform-dependent and may be overwritten.
@@ -463,13 +473,21 @@ var Dep = function () {
463473} ( ) ;
464474
465475Dep . target = null ;
476+ var targetStack = [ ] ;
477+
478+ function pushTarget ( _target ) {
479+ if ( Dep . target ) targetStack . push ( Dep . target ) ;
480+ Dep . target = _target ;
481+ }
466482
467- // we have two separate queues: one for directive updates
468- // and one for user watcher registered via $watch().
469- // we want to guarantee directive updates to be called
470- // before user watchers so that when user watchers are
471- // triggered, the DOM would have already been in updated
472- // state.
483+ function popTarget ( ) {
484+ Dep . target = targetStack . pop ( ) ;
485+ }
486+
487+ // We have two separate queues: one for internal component re-render updates
488+ // and one for user watcher registered via $watch(). We want to guarantee
489+ // re-render updates to be called before user watchers so that when user
490+ // watchers are triggered, the DOM would already be in updated state.
473491
474492var queue = [ ] ;
475493var userQueue = [ ] ;
@@ -501,6 +519,11 @@ function flushSchedulerQueue() {
501519 if ( queue . length ) {
502520 return flushSchedulerQueue ( ) ;
503521 }
522+ // devtool hook
523+ /* istanbul ignore if */
524+ if ( devtools && config . devtools ) {
525+ devtools . emit ( 'flush' ) ;
526+ }
504527 resetSchedulerState ( ) ;
505528}
506529
@@ -559,7 +582,6 @@ function queueWatcher(watcher) {
559582}
560583
561584var uid$1 = 0 ;
562- var prevTarget = void 0 ;
563585
564586/**
565587 * A watcher parses an expression, collects dependencies,
@@ -577,6 +599,7 @@ var Watcher = function () {
577599 this . deep = ! ! options . deep ;
578600 this . user = ! ! options . user ;
579601 this . lazy = ! ! options . lazy ;
602+ this . sync = ! ! options . sync ;
580603 this . expression = expOrFn . toString ( ) ;
581604 this . cb = cb ;
582605 this . id = ++ uid$1 ; // uid for batching
@@ -605,7 +628,7 @@ var Watcher = function () {
605628
606629
607630 Watcher . prototype . get = function get ( ) {
608- this . beforeGet ( ) ;
631+ pushTarget ( this ) ;
609632 var value = void 0 ;
610633 try {
611634 value = this . getter . call ( this . vm , this . vm ) ;
@@ -632,20 +655,11 @@ var Watcher = function () {
632655 if ( this . deep ) {
633656 traverse ( value ) ;
634657 }
635- this . afterGet ( ) ;
658+ popTarget ( ) ;
659+ this . cleanupDeps ( ) ;
636660 return value ;
637661 } ;
638662
639- /**
640- * Prepare for dependency collection.
641- */
642-
643-
644- Watcher . prototype . beforeGet = function beforeGet ( ) {
645- prevTarget = Dep . target ;
646- Dep . target = this ;
647- } ;
648-
649663 /**
650664 * Add a dependency to this directive.
651665 */
@@ -667,8 +681,7 @@ var Watcher = function () {
667681 */
668682
669683
670- Watcher . prototype . afterGet = function afterGet ( ) {
671- Dep . target = prevTarget ;
684+ Watcher . prototype . cleanupDeps = function cleanupDeps ( ) {
672685 var i = this . deps . length ;
673686 while ( i -- ) {
674687 var dep = this . deps [ i ] ;
@@ -693,8 +706,11 @@ var Watcher = function () {
693706
694707
695708 Watcher . prototype . update = function update ( ) {
709+ /* istanbul ignore else */
696710 if ( this . lazy ) {
697711 this . dirty = true ;
712+ } else if ( this . sync ) {
713+ this . run ( ) ;
698714 } else {
699715 queueWatcher ( this ) ;
700716 }
@@ -729,12 +745,8 @@ var Watcher = function () {
729745
730746
731747 Watcher . prototype . evaluate = function evaluate ( ) {
732- // avoid overwriting another watcher that is being
733- // collected.
734- var current = Dep . target ;
735748 this . value = this . get ( ) ;
736749 this . dirty = false ;
737- Dep . target = current ;
738750 } ;
739751
740752 /**
@@ -1407,6 +1419,7 @@ function lifecycleMixin(Vue) {
14071419 if ( vm . _isMounted ) {
14081420 callHook ( vm , 'beforeUpdate' ) ;
14091421 }
1422+ var prevEl = vm . $el ;
14101423 if ( ! vm . _vnode ) {
14111424 // Vue.prototype.__patch__ is injected in entry points
14121425 // based on the rendering backend used.
@@ -1415,6 +1428,13 @@ function lifecycleMixin(Vue) {
14151428 vm . $el = vm . __patch__ ( vm . _vnode , vnode ) ;
14161429 }
14171430 vm . _vnode = vnode ;
1431+ // update __vue__ reference
1432+ if ( prevEl ) {
1433+ prevEl . __vue__ = null ;
1434+ }
1435+ if ( vm . $el ) {
1436+ vm . $el . __vue__ = vm ;
1437+ }
14181438 // update parent vnode element after patch
14191439 var parentNode = vm . $options . _parentVnode ;
14201440 if ( parentNode ) {
@@ -1500,6 +1520,10 @@ function lifecycleMixin(Vue) {
15001520 callHook ( vm , 'destroyed' ) ;
15011521 // turn off all instance listeners.
15021522 vm . $off ( ) ;
1523+ // remove __vue__ reference
1524+ if ( vm . $el ) {
1525+ vm . $el . __vue__ = null ;
1526+ }
15031527 } ;
15041528}
15051529
@@ -1924,6 +1948,11 @@ function renderMixin(Vue) {
19241948 }
19251949 }
19261950 } ;
1951+
1952+ // expose v-on keyCodes
1953+ Vue . prototype . _k = function ( key ) {
1954+ return config . keyCodes [ key ] ;
1955+ } ;
19271956}
19281957
19291958function resolveSlots ( vm , renderChildren ) {
@@ -2706,7 +2735,17 @@ var builtInComponents = {
27062735} ;
27072736
27082737function initGlobalAPI ( Vue ) {
2709- Vue . config = config ;
2738+ // config
2739+ var configDef = { } ;
2740+ configDef . get = function ( ) {
2741+ return config ;
2742+ } ;
2743+ if ( process . env . NODE_ENV !== 'production' ) {
2744+ configDef . set = function ( ) {
2745+ warn ( 'Do not replace the Vue.config object, set individual fields instead.' ) ;
2746+ } ;
2747+ }
2748+ Object . defineProperty ( Vue , 'config' , configDef ) ;
27102749 Vue . util = util ;
27112750 Vue . set = set ;
27122751 Vue . delete = del ;
@@ -2733,7 +2772,7 @@ Object.defineProperty(Vue.prototype, '$isServer', {
27332772 }
27342773} ) ;
27352774
2736- Vue . version = '2.0.0-alpha.5 ' ;
2775+ Vue . version = '2.0.0-alpha.6 ' ;
27372776
27382777// attributes that should be using props for binding
27392778var mustUseProp = makeMap ( 'value,selected,checked,muted' ) ;
@@ -4025,6 +4064,8 @@ var modules = platformModules.concat(baseModules);
40254064
40264065var patch = createPatchFunction ( { nodeOps : nodeOps , modules : modules } ) ;
40274066
4067+ var modelableTagRE = / ^ i n p u t | s e l e c t | t e x t a r e a | v u e - c o m p o n e n t - [ 0 - 9 ] + ( - [ 0 - 9 a - z A - Z _ \- ] * ) ? $ / ;
4068+
40284069/* istanbul ignore if */
40294070if ( isIE9 ) {
40304071 // http://www.matts411.com/post/internet-explorer-9-oninput/
@@ -4039,7 +4080,7 @@ if (isIE9) {
40394080var model = {
40404081 bind : function bind ( el , binding , vnode ) {
40414082 if ( process . env . NODE_ENV !== 'production' ) {
4042- if ( ! / i n p u t | s e l e c t | t e x t a r e a / . test ( vnode . tag ) ) {
4083+ if ( ! modelableTagRE . test ( vnode . tag ) ) {
40434084 warn ( 'v-model is not supported on element type: <' + vnode . tag + '>. ' + 'If you are working with contenteditable, it\'s recommended to ' + 'wrap a library dedicated for that purpose inside a custom component.' , vnode . context ) ;
40444085 }
40454086 }
@@ -4247,4 +4288,16 @@ Vue.prototype.$mount = function (el, hydrating) {
42474288 return this . _mount ( el && query ( el ) , hydrating ) ;
42484289} ;
42494290
4291+ // devtools global hook
4292+ /* istanbul ignore next */
4293+ setTimeout ( function ( ) {
4294+ if ( config . devtools ) {
4295+ if ( devtools ) {
4296+ devtools . emit ( 'init' , Vue ) ;
4297+ } else if ( process . env . NODE_ENV !== 'production' && inBrowser && / C h r o m e \/ \d + / . test ( window . navigator . userAgent ) ) {
4298+ console . log ( 'Download the Vue Devtools for a better development experience:\n' + 'https://github.com/vuejs/vue-devtools' ) ;
4299+ }
4300+ }
4301+ } , 0 ) ;
4302+
42504303module . exports = Vue ;
0 commit comments