From 16363d8000a484b428a16eb07d8bd0f19c4b4337 Mon Sep 17 00:00:00 2001 From: Vojta Jina Date: Fri, 4 Nov 2011 18:33:12 -0700 Subject: refactor(ng:view, ng:include): pass cache instance into $http Instead of doing all the stuff in these widgets (checking cache, etc..) we can rely on $http now... --- src/widgets.js | 59 +++++++++++++++++++--------------------------------------- 1 file changed, 19 insertions(+), 40 deletions(-) (limited to 'src') diff --git a/src/widgets.js b/src/widgets.js index 861e61bf..c89f4179 100644 --- a/src/widgets.js +++ b/src/widgets.js @@ -112,18 +112,6 @@ angularWidget('ng:include', function(element){ useScope = scope.$eval(scopeExp), fromCache; - function updateContent(content) { - element.html(content); - if (useScope) { - childScope = useScope; - } else { - releaseScopes.push(childScope = scope.$new()); - } - compiler.compile(element)(childScope); - $autoScroll(); - scope.$eval(onloadExp); - } - function clearContent() { childScope = null; element.html(''); @@ -133,16 +121,17 @@ angularWidget('ng:include', function(element){ releaseScopes.pop().$destroy(); } if (src) { - if ((fromCache = $templateCache.get(src))) { - scope.$evalAsync(function() { - updateContent(fromCache); - }); - } else { - $http.get(src).on('success', function(response) { - updateContent(response); - $templateCache.put(src, response); - }).on('error', clearContent); - } + $http.get(src, {cache: $templateCache}).on('success', function(response) { + element.html(response); + if (useScope) { + childScope = useScope; + } else { + releaseScopes.push(childScope = scope.$new()); + } + compiler.compile(element)(childScope); + $autoScroll(); + scope.$eval(onloadExp); + }).on('error', clearContent); } else { clearContent(); } @@ -586,30 +575,20 @@ angularWidget('ng:view', function(element) { var template = $route.current && $route.current.template, fromCache; - function updateContent(content) { - element.html(content); - compiler.compile(element)($route.current.scope); - } - function clearContent() { element.html(''); } if (template) { - if ((fromCache = $templateCache.get(template))) { - scope.$evalAsync(function() { - updateContent(fromCache); - }); - } else { - // xhr's callback must be async, see commit history for more info - $http.get(template).on('success', function(response) { - // ignore callback if another route change occured since - if (newChangeCounter == changeCounter) - updateContent(response); - $templateCache.put(template, response); + // xhr's callback must be async, see commit history for more info + $http.get(template, {cache: $templateCache}).on('success', function(response) { + // ignore callback if another route change occured since + if (newChangeCounter == changeCounter) { + element.html(response); + compiler.compile(element)($route.current.scope); $autoScroll(); - }).on('error', clearContent); - } + } + }).on('error', clearContent); } else { clearContent(); } -- cgit v1.2.3