11var endEvents = sniffEndEvents ( ) ,
22 config = require ( './config' ) ,
3+ // batch enter animations so we only force the layout once
4+ Batcher = require ( './batcher' ) ,
5+ batcher = new Batcher ( ) ,
36 // exit codes for testing
47 codes = {
58 CSS_E : 1 ,
@@ -14,6 +17,12 @@ var endEvents = sniffEndEvents(),
1417 SKIP : - 6
1518 }
1619
20+ // force a layout so transition can be triggered
21+ batcher . _preFlush = function ( ) {
22+ /* jshint unused: false */
23+ var forceLayout = document . body . clientHeight
24+ }
25+
1726/**
1827 * stage:
1928 * 1 = enter
@@ -70,19 +79,19 @@ function applyTransitionClass (el, stage, changeState, animation) {
7079
7180 // if the browser supports transition,
7281 // it must have classList...
73- var onEnd ,
74- classList = el . classList ,
75- lastLeaveCallback = el . vue_trans_cb ,
76- enterClass = config . enterClass ,
77- leaveClass = config . leaveClass ,
78- isAnimation = animation === '' ,
82+ var onEnd , job ,
83+ classList = el . classList ,
84+ existingCallback = el . vue_trans_cb ,
85+ enterClass = config . enterClass ,
86+ leaveClass = config . leaveClass ,
87+ isAnimation = animation === '' ,
7988 endEvent = isAnimation
8089 ? endEvents . anim
8190 : endEvents . trans
8291
83- // cancel unfinished leave transition
84- if ( lastLeaveCallback ) {
85- el . removeEventListener ( endEvent , lastLeaveCallback )
92+ // cancel unfinished callbacks and jobs
93+ if ( existingCallback ) {
94+ el . removeEventListener ( endEvent , existingCallback )
8695 classList . remove ( enterClass )
8796 classList . remove ( leaveClass )
8897 el . vue_trans_cb = null
@@ -96,24 +105,27 @@ function applyTransitionClass (el, stage, changeState, animation) {
96105 }
97106 // append
98107 changeState ( )
99- // force a layout so transition can be triggered
100- /* jshint unused: false */
101- var forceLayout = el . clientHeight
108+ job = { }
102109 // trigger transition
103110 if ( ! isAnimation ) {
104- classList . remove ( enterClass )
111+ job . execute = function ( ) {
112+ classList . remove ( enterClass )
113+ }
105114 } else {
106- classList . add ( enterClass )
107115 onEnd = function ( e ) {
108116 if ( e . target === el ) {
109117 el . removeEventListener ( endEvent , onEnd )
110118 el . vue_trans_cb = null
111119 classList . remove ( enterClass )
112120 }
113121 }
114- el . addEventListener ( endEvent , onEnd )
115- el . vue_trans_cb = onEnd
122+ job . execute = function ( ) {
123+ classList . add ( enterClass )
124+ el . addEventListener ( endEvent , onEnd )
125+ el . vue_trans_cb = onEnd
126+ }
116127 }
128+ batcher . push ( job )
117129 return codes . CSS_E
118130
119131 } else { // leave
0 commit comments