Skip to content

Commit c4e8c8f

Browse files
committed
Merge pull request Urigo#307 from barbatus/iron-router-handler1
Reverts back recent changes to the onAfterAction handler.
2 parents 092c522 + b0745e0 commit c4e8c8f

File tree

1 file changed

+8
-37
lines changed

1 file changed

+8
-37
lines changed

angular-meteor.js

Lines changed: 8 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -17,44 +17,15 @@ var angularMeteor = angular.module('angular-meteor', [
1717
angularMeteor.run(['$compile', '$document', '$rootScope', function ($compile, $document, $rootScope) {
1818
// Recompile after iron:router builds page
1919
if(typeof Router != 'undefined') {
20+
var appLoaded = false;
2021
Router.onAfterAction(function(req, res, next) {
21-
// Since Router.current().ready() is reactive we wrap it in Tracker.nonreactive
22-
// to avoid re-runs.
23-
Tracker.nonreactive(function() {
24-
Tracker.afterFlush(function() {
25-
var route = Router.current();
26-
if (route.ready()) {
27-
// Since onAfterAction runs always twice when a route has waitOn's subscriptions,
28-
// we need to handle case when data is already loaded at the moment
29-
// Tracker.afterFlush executes which means it will run twice with
30-
// Router.current().ready equals true.
31-
// That's we save state to an additional auxiliry variable _done.
32-
if (!route.state.get('__rendered')) {
33-
// Checks if document's been compiled to the moment.
34-
// If yes, compile only newly inserted parts.
35-
if (route.state.get('__compiled')) {
36-
for (var prop in route._layout._regions) {
37-
var region = route._layout._regions[prop];
38-
var node = region.view._domrange.firstNode();
39-
while (node) {
40-
$compile(node)($rootScope);
41-
node = node.nextSibling;
42-
}
43-
}
44-
} else {
45-
$compile($document)($rootScope);
46-
}
47-
if (!$rootScope.$$phase) $rootScope.$apply();
48-
route.state.set('__rendered', true);
49-
}
50-
} else {
51-
// Compiles and applies scope for the first time when current route is not ready.
52-
$compile($document)($rootScope);
53-
if (!$rootScope.$$phase) $rootScope.$apply();
54-
route.state.set('__compiled', true);
55-
}
56-
});
57-
});
22+
Tracker.afterFlush(function() {
23+
if (!appLoaded) {
24+
$compile($document)($rootScope);
25+
if (!$rootScope.$$phase) $rootScope.$apply();
26+
appLoaded = true;
27+
}
28+
})
5829
});
5930
}
6031
}]);

0 commit comments

Comments
 (0)