@@ -377,10 +377,15 @@ var config = require('./config'),
377
377
/**
378
378
* Set config options
379
379
*/
380
- ViewModel . config = function ( opts ) {
381
- if ( opts ) {
380
+ ViewModel . config = function ( opts , val ) {
381
+ if ( typeof opts === 'string' ) {
382
+ if ( val === undefined ) {
383
+ return config [ opts ]
384
+ } else {
385
+ config [ opts ] = val
386
+ }
387
+ } else {
382
388
utils . extend ( config , opts )
383
- if ( opts . prefix ) updatePrefix ( )
384
389
}
385
390
return this
386
391
}
@@ -521,29 +526,6 @@ function mergeHook (fn, parentFn) {
521
526
}
522
527
}
523
528
524
- /**
525
- * Update prefix for some special directives
526
- * that are used in compilation.
527
- */
528
- var specialAttributes = [
529
- 'pre' ,
530
- 'text' ,
531
- 'repeat' ,
532
- 'partial' ,
533
- 'component' ,
534
- 'component-id' ,
535
- 'transition'
536
- ]
537
-
538
- function updatePrefix ( ) {
539
- specialAttributes . forEach ( setPrefix )
540
- }
541
-
542
- function setPrefix ( attr ) {
543
- config . attrs [ attr ] = config . prefix + '-' + attr
544
- }
545
-
546
- updatePrefix ( )
547
529
module . exports = ViewModel
548
530
} ) ;
549
531
require . register ( "vue/src/emitter.js" , function ( exports , require , module ) {
@@ -569,16 +551,42 @@ try {
569
551
module . exports = Emitter
570
552
} ) ;
571
553
require . register ( "vue/src/config.js" , function ( exports , require , module ) {
572
- module . exports = {
554
+ var prefix = 'v' ,
555
+ specialAttributes = [
556
+ 'pre' ,
557
+ 'text' ,
558
+ 'repeat' ,
559
+ 'partial' ,
560
+ 'component' ,
561
+ 'component-id' ,
562
+ 'transition'
563
+ ] ,
564
+ config = module . exports = {
565
+
566
+ async : true ,
567
+ debug : false ,
568
+ silent : false ,
569
+ enterClass : 'v-enter' ,
570
+ leaveClass : 'v-leave' ,
571
+ attrs : { } ,
572
+
573
+ get prefix ( ) {
574
+ return prefix
575
+ } ,
576
+ set prefix ( val ) {
577
+ prefix = val
578
+ updatePrefix ( )
579
+ }
580
+
581
+ }
573
582
574
- prefix : 'v' ,
575
- debug : false ,
576
- silent : false ,
577
- enterClass : 'v-enter' ,
578
- leaveClass : 'v-leave' ,
579
- attrs : { }
580
-
583
+ function updatePrefix ( ) {
584
+ specialAttributes . forEach ( function ( attr ) {
585
+ config . attrs [ attr ] = prefix + '-' + attr
586
+ } )
581
587
}
588
+
589
+ updatePrefix ( )
582
590
} ) ;
583
591
require . register ( "vue/src/utils.js" , function ( exports , require , module ) {
584
592
var config = require ( './config' ) ,
@@ -588,10 +596,13 @@ var config = require('./config'),
588
596
console = window . console ,
589
597
ViewModel // late def
590
598
591
- var defer =
592
- window . webkitRequestAnimationFrame ||
593
- window . requestAnimationFrame ||
594
- window . setTimeout
599
+ // PhantomJS doesn't support rAF, yet it has the global
600
+ // variable exposed. Use setTimeout so tests can work.
601
+ var defer = navigator . userAgent . indexOf ( 'PhantomJS' ) > - 1
602
+ ? window . setTimeout
603
+ : ( window . webkitRequestAnimationFrame ||
604
+ window . requestAnimationFrame ||
605
+ window . setTimeout )
595
606
596
607
/**
597
608
* Create a prototype-less object
@@ -771,7 +782,7 @@ var utils = module.exports = {
771
782
} ,
772
783
773
784
/**
774
- * Defer DOM updates
785
+ * used to defer batch updates
775
786
*/
776
787
nextTick : function ( cb ) {
777
788
defer ( cb , 0 )
@@ -1586,6 +1597,9 @@ function getTargetVM (vm, path) {
1586
1597
module . exports = ViewModel
1587
1598
} ) ;
1588
1599
require . register ( "vue/src/binding.js" , function ( exports , require , module ) {
1600
+ var batcher = require ( './batcher' ) ,
1601
+ id = 0
1602
+
1589
1603
/**
1590
1604
* Binding class.
1591
1605
*
@@ -1594,6 +1608,7 @@ require.register("vue/src/binding.js", function(exports, require, module){
1594
1608
* and multiple computed property dependents
1595
1609
*/
1596
1610
function Binding ( compiler , key , isExp , isFn ) {
1611
+ this . id = id ++
1597
1612
this . value = undefined
1598
1613
this . isExp = ! ! isExp
1599
1614
this . isFn = isFn
@@ -1603,6 +1618,7 @@ function Binding (compiler, key, isExp, isFn) {
1603
1618
this . instances = [ ]
1604
1619
this . subs = [ ]
1605
1620
this . deps = [ ]
1621
+ this . unbound = false
1606
1622
}
1607
1623
1608
1624
var BindingProto = Binding . prototype
@@ -1612,9 +1628,13 @@ var BindingProto = Binding.prototype
1612
1628
*/
1613
1629
BindingProto . update = function ( value ) {
1614
1630
this . value = value
1631
+ batcher . queue ( this , 'update' )
1632
+ }
1633
+
1634
+ BindingProto . _update = function ( ) {
1615
1635
var i = this . instances . length
1616
1636
while ( i -- ) {
1617
- this . instances [ i ] . update ( value )
1637
+ this . instances [ i ] . update ( this . value )
1618
1638
}
1619
1639
this . pub ( )
1620
1640
}
@@ -1624,6 +1644,10 @@ BindingProto.update = function (value) {
1624
1644
* Force all instances to re-evaluate themselves
1625
1645
*/
1626
1646
BindingProto . refresh = function ( ) {
1647
+ batcher . queue ( this , 'refresh' )
1648
+ }
1649
+
1650
+ BindingProto . _refresh = function ( ) {
1627
1651
var i = this . instances . length
1628
1652
while ( i -- ) {
1629
1653
this . instances [ i ] . refresh ( )
@@ -1646,6 +1670,11 @@ BindingProto.pub = function () {
1646
1670
* Unbind the binding, remove itself from all of its dependencies
1647
1671
*/
1648
1672
BindingProto . unbind = function ( ) {
1673
+ // Indicate this has been unbound.
1674
+ // It's possible this binding will be in
1675
+ // the batcher's flush queue when its owner
1676
+ // compiler has already been destroyed.
1677
+ this . unbound = true
1649
1678
var i = this . instances . length
1650
1679
while ( i -- ) {
1651
1680
this . instances [ i ] . unbind ( )
@@ -2668,6 +2697,48 @@ function sniffTransitionEndEvent () {
2668
2697
}
2669
2698
}
2670
2699
} ) ;
2700
+ require . register ( "vue/src/batcher.js" , function ( exports , require , module ) {
2701
+ var config = require ( './config' ) ,
2702
+ utils = require ( './utils' ) ,
2703
+ queue , has , waiting
2704
+
2705
+ reset ( )
2706
+
2707
+ exports . queue = function ( binding , method ) {
2708
+ if ( ! config . async ) {
2709
+ binding [ '_' + method ] ( )
2710
+ return
2711
+ }
2712
+ if ( ! has [ binding . id ] ) {
2713
+ queue . push ( {
2714
+ binding : binding ,
2715
+ method : method
2716
+ } )
2717
+ has [ binding . id ] = true
2718
+ if ( ! waiting ) {
2719
+ waiting = true
2720
+ utils . nextTick ( flush )
2721
+ }
2722
+ }
2723
+ }
2724
+
2725
+ function flush ( ) {
2726
+ for ( var i = 0 ; i < queue . length ; i ++ ) {
2727
+ var task = queue [ i ] ,
2728
+ b = task . binding
2729
+ if ( b . unbound ) continue
2730
+ b [ '_' + task . method ] ( )
2731
+ has [ b . id ] = false
2732
+ }
2733
+ reset ( )
2734
+ }
2735
+
2736
+ function reset ( ) {
2737
+ queue = [ ]
2738
+ has = utils . hash ( )
2739
+ waiting = false
2740
+ }
2741
+ } ) ;
2671
2742
require . register ( "vue/src/directives/index.js" , function ( exports , require , module ) {
2672
2743
var utils = require ( '../utils' ) ,
2673
2744
transition = require ( '../transition' )
@@ -3143,15 +3214,14 @@ module.exports = {
3143
3214
try {
3144
3215
cursorPos = el . selectionStart
3145
3216
} catch ( e ) { }
3146
- // `input` event has weird updating issue with
3147
- // International (e.g. Chinese) input methods,
3148
- // have to use a Timeout to hack around it...
3149
- setTimeout ( function ( ) {
3150
- self . vm . $set ( self . key , el [ attr ] )
3217
+ self . vm . $set ( self . key , el [ attr ] )
3218
+ // since updates are async
3219
+ // we need to reset cursor position async too
3220
+ utils . nextTick ( function ( ) {
3151
3221
if ( cursorPos !== undefined ) {
3152
3222
el . setSelectionRange ( cursorPos , cursorPos )
3153
3223
}
3154
- } , 0 )
3224
+ } )
3155
3225
}
3156
3226
: function ( ) {
3157
3227
// no filters, don't let it trigger update()
@@ -3166,9 +3236,9 @@ module.exports = {
3166
3236
if ( isIE9 ) {
3167
3237
self . onCut = function ( ) {
3168
3238
// cut event fires before the value actually changes
3169
- setTimeout ( function ( ) {
3239
+ utils . nextTick ( function ( ) {
3170
3240
self . set ( )
3171
- } , 0 )
3241
+ } )
3172
3242
}
3173
3243
self . onDel = function ( e ) {
3174
3244
if ( e . keyCode === 46 || e . keyCode === 8 ) {
0 commit comments