1
+ var requestAnimFrame = ( function ( ) {
2
+ return window . requestAnimationFrame || window . webkitRequestAnimationFrame || window . mozRequestAnimationFrame || function ( callback ) {
3
+ setTimeout ( callback , 1000 / 60 ) ;
4
+ } ;
5
+ } ) ( ) ;
1
6
BlazeRenderer = ( function ( ) {
2
7
function BlazeRenderer ( rootEl ) {
3
8
this . rootEl = rootEl ;
@@ -14,7 +19,7 @@ BlazeRenderer = (function() {
14
19
}
15
20
16
21
BlazeRenderer . prototype . render = function ( layout , template , data ) {
17
- var _data , _template , _layout ;
22
+ var _data , _template , _layout , self = this ;
18
23
19
24
_template = typeof Template !== "undefined" && Template !== null ? Template [ template ] : void 0 ;
20
25
_layout = typeof Template !== "undefined" && Template !== null ? Template [ layout ] : void 0 ;
@@ -36,16 +41,6 @@ BlazeRenderer = (function() {
36
41
_data = _ . extend ( _data , data ) ;
37
42
}
38
43
39
- if ( this . current . template === template ) {
40
- var self = this ;
41
- this . reactTemplate . set ( null ) ;
42
- Meteor . setTimeout ( function ( ) {
43
- self . reactTemplate . set ( template ) ;
44
- } , 1 ) ;
45
- } else {
46
- this . reactTemplate . set ( template ) ;
47
- }
48
-
49
44
if ( this . current . layout !== layout ) {
50
45
if ( this . old ) {
51
46
Blaze . remove ( this . old ) ;
@@ -54,11 +49,21 @@ BlazeRenderer = (function() {
54
49
var getData = function getData ( ) {
55
50
return _data ;
56
51
} ;
52
+
57
53
this . old = Blaze . renderWithData ( _layout , getData , this . rootEl ( ) ) ;
58
54
} else {
59
55
this . old . dataVar . set ( _data ) ;
60
56
}
61
57
58
+ if ( this . current . template === template ) {
59
+ this . reactTemplate . set ( null ) ;
60
+ requestAnimFrame ( function updateTemplate ( ) {
61
+ self . reactTemplate . set ( template ) ;
62
+ } ) ;
63
+ } else {
64
+ this . reactTemplate . set ( template ) ;
65
+ }
66
+
62
67
this . current . layout = layout ;
63
68
this . current . template = template ;
64
69
}
0 commit comments