Skip to content

Commit 5c1eaed

Browse files
committed
v2.12.6
- Rendering optimisation via `requestAnimationFrame`
1 parent 1ac612a commit 5c1eaed

File tree

3 files changed

+18
-13
lines changed

3 files changed

+18
-13
lines changed

.versions

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ [email protected]
2121
2222
2323
24-
24+
2525
2626
2727

client/renderer.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
var requestAnimFrame = (function() {
2+
return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || function(callback) {
3+
setTimeout(callback, 1000 / 60);
4+
};
5+
})();
16
BlazeRenderer = (function() {
27
function BlazeRenderer(rootEl) {
38
this.rootEl = rootEl;
@@ -14,7 +19,7 @@ BlazeRenderer = (function() {
1419
}
1520

1621
BlazeRenderer.prototype.render = function(layout, template, data) {
17-
var _data, _template, _layout;
22+
var _data, _template, _layout, self = this;
1823

1924
_template = typeof Template !== "undefined" && Template !== null ? Template[template] : void 0;
2025
_layout = typeof Template !== "undefined" && Template !== null ? Template[layout] : void 0;
@@ -36,16 +41,6 @@ BlazeRenderer = (function() {
3641
_data = _.extend(_data, data);
3742
}
3843

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-
4944
if (this.current.layout !== layout) {
5045
if (this.old) {
5146
Blaze.remove(this.old);
@@ -54,11 +49,21 @@ BlazeRenderer = (function() {
5449
var getData = function getData () {
5550
return _data;
5651
};
52+
5753
this.old = Blaze.renderWithData(_layout, getData, this.rootEl());
5854
} else {
5955
this.old.dataVar.set(_data);
6056
}
6157

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+
6267
this.current.layout = layout;
6368
this.current.template = template;
6469
}

package.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package.describe({
22
name: 'ostrio:flow-router-extra',
33
summary: 'Carefully extended flow-router with waitOn and template context',
4-
version: '2.12.5',
4+
version: '2.12.6',
55
git: 'https://github.com/VeliovGroup/flow-router'
66
});
77

0 commit comments

Comments
 (0)