Skip to content

Commit 5666cc3

Browse files
committed
1 parent 92d023e commit 5666cc3

File tree

3 files changed

+54
-7
lines changed

3 files changed

+54
-7
lines changed

client/_init.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { Meteor } from 'meteor/meteor';
2+
import { _ } from 'meteor/underscore';
23
import Router from './router.js';
34
import Route from './route.js';
45
import Group from './group.js';
56
import Triggers from './triggers.js';
67
import BlazeRenderer from './renderer.js';
78
import helpersInit from './active.route.js';
9+
import { requestAnimFrame } from './modules.js';
810

911
const FlowRouter = new Router();
1012
FlowRouter.Router = Router;
@@ -14,6 +16,51 @@ FlowRouter.Route = Route;
1416
Meteor.startup(() => {
1517
if(!FlowRouter._askedToWait && !FlowRouter._initialized) {
1618
FlowRouter.initialize();
19+
20+
FlowRouter.route('/___refresh/:layout/:template/:oldRoute?', {
21+
name: '___refresh',
22+
action(params, queryParams) {
23+
this.render(params.layout, params.template, () => {
24+
requestAnimFrame(() => {
25+
if (params.oldRoute) {
26+
try {
27+
if (history.length) {
28+
window.history.go(-1);
29+
} else {
30+
FlowRouter.go(params.oldRoute, (queryParams.oldParams ? JSON.parse(queryParams.oldParams) : {}));
31+
}
32+
} catch (e) {
33+
FlowRouter.go('/');
34+
}
35+
} else {
36+
if (history.length) {
37+
window.history.go(-1);
38+
} else {
39+
FlowRouter.go('/');
40+
}
41+
}
42+
});
43+
});
44+
}
45+
});
46+
47+
FlowRouter.refresh = (layout, template) => {
48+
if (!layout || !_.isString(layout)) {
49+
throw new Meteor.Error(400, '[FlowRouter.refresh(layout, template)] -> "layout" must be a String!');
50+
}
51+
52+
if (!template || !_.isString(template)) {
53+
throw new Meteor.Error(400, '[FlowRouter.refresh(layout, template)] -> "template" must be a String!');
54+
}
55+
56+
FlowRouter.go('___refresh', {
57+
oldRoute: FlowRouter._current.route.name,
58+
layout,
59+
template
60+
}, {
61+
oldParams: JSON.stringify(FlowRouter._current.params || {})
62+
});
63+
};
1764
}
1865
});
1966

client/modules.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
const page = require('page');
22
const qs = require('qs');
3+
const requestAnimFrame = (() => {
4+
return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || function (callback) {
5+
setTimeout(callback, 1000 / 60);
6+
};
7+
})();
38

4-
export { page, qs };
9+
export { page, qs, requestAnimFrame };

client/renderer.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@ import { _ } from 'meteor/underscore';
22
import { Blaze } from 'meteor/blaze';
33
import { Meteor } from 'meteor/meteor';
44
import { Template } from 'meteor/templating';
5-
6-
const requestAnimFrame = (() => {
7-
return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || function (callback) {
8-
setTimeout(callback, 1000 / 60);
9-
};
10-
})();
5+
import { requestAnimFrame } from './modules.js';
116

127
class BlazeRenderer {
138
constructor(opts = {}) {

0 commit comments

Comments
 (0)