mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-24 12:05:46 +08:00
make xhr.cache optionally synchronous
- add `sync` flag xhr.cache - change ng:include to use the sync flag - change ng:view to use the sync flag The end result is that there are fewer repaints in the browser, which means less "blinking" that user sees.
This commit is contained in:
@@ -107,6 +107,22 @@ describe('$xhr.cache', function() {
|
||||
});
|
||||
|
||||
|
||||
it('should call callback synchronously when sync flag is on', function() {
|
||||
$browserXhr.expectGET('/url').respond('+');
|
||||
cache('GET', '/url', null, callback, false, true);
|
||||
expect(log).toEqual(''); //callback hasn't executed
|
||||
|
||||
$browserXhr.flush();
|
||||
expect(log).toEqual('"+";'); //callback has executed
|
||||
|
||||
cache('GET', '/url', null, callback, false, true);
|
||||
expect(log).toEqual('"+";"+";'); //callback has executed
|
||||
|
||||
$browser.defer.flush();
|
||||
expect(log).toEqual('"+";"+";'); //callback was not called again any more
|
||||
});
|
||||
|
||||
|
||||
it('should call eval after callbacks for both cache hit and cache miss execute', function() {
|
||||
var eval = this.spyOn(scope, '$eval').andCallThrough();
|
||||
|
||||
|
||||
@@ -610,7 +610,6 @@ describe("widget", function(){
|
||||
scope.url = 'myUrl';
|
||||
scope.$service('$xhr.cache').data.myUrl = {value:'{{name}}'};
|
||||
scope.$eval();
|
||||
scope.$service('$browser').defer.flush();
|
||||
expect(element.text()).toEqual('misko');
|
||||
dealoc(scope);
|
||||
});
|
||||
@@ -623,7 +622,6 @@ describe("widget", function(){
|
||||
scope.url = 'myUrl';
|
||||
scope.$service('$xhr.cache').data.myUrl = {value:'{{name}}'};
|
||||
scope.$eval();
|
||||
scope.$service('$browser').defer.flush();
|
||||
|
||||
expect(element.text()).toEqual('igor');
|
||||
|
||||
@@ -640,7 +638,6 @@ describe("widget", function(){
|
||||
scope.url = 'myUrl';
|
||||
scope.$service('$xhr.cache').data.myUrl = {value:'{{c=c+1}}'};
|
||||
scope.$eval();
|
||||
scope.$service('$browser').defer.flush();
|
||||
|
||||
// this one should really be just '1', but due to lack of real events things are not working
|
||||
// properly. see discussion at: http://is.gd/ighKk
|
||||
@@ -657,7 +654,6 @@ describe("widget", function(){
|
||||
scope.url = 'myUrl';
|
||||
scope.$service('$xhr.cache').data.myUrl = {value:'my partial'};
|
||||
scope.$eval();
|
||||
scope.$service('$browser').defer.flush();
|
||||
expect(element.text()).toEqual('my partial');
|
||||
expect(scope.loaded).toBe(true);
|
||||
dealoc(element);
|
||||
|
||||
Reference in New Issue
Block a user