Skip to content
This repository has been archived by the owner on Jan 29, 2024. It is now read-only.

Commit

Permalink
fix(service): partial loader service refetches list of parts
Browse files Browse the repository at this point in the history
Ensures that the partial loader service refetches the list of parts when its promise resolves in case the list of parts have changed in the intervening time

Fixes #1326
  • Loading branch information
Anthony Cleaver authored and knalli committed Dec 27, 2015
1 parent cafc0cf commit 069eafd
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/service/loader-partial.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ function $translatePartialLoader() {
return $q.all(loaders)
.then(function() {
var table = {};
prioritizedParts = getPrioritizedParts();
angular.forEach(prioritizedParts, function(part) {
deepExtend(table, part.tables[options.key]);
});
Expand Down
55 changes: 55 additions & 0 deletions test/unit/service/loader-partial.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,61 @@ describe('pascalprecht.translate', function() {
$httpBackend.flush();
});
});

it('should handle the parts being resolve out of the order which they were called', function() {
var $q,
requests = [];

module(function($provide) {
$provide.value('$http', function() {
var request = $q.defer();

requests.push(request);

return request.promise;
});
});

inject(function($translatePartialLoader, _$q_, $rootScope) {
var table;

$q = _$q_;

$translatePartialLoader.addPart('part1');
$translatePartialLoader.addPart('part2');
$translatePartialLoader({
key : 'en',
urlTemplate : '/locales/{part}-{lang}.json'
}).then(function(data) {
table = data;
}, function() {
table = {};
});

$translatePartialLoader.addPart('part3');
$translatePartialLoader({
key : 'en',
urlTemplate : '/locales/{part}-{lang}.json'
}).then(function(data) {
table = data;
}, function() {
table = {};
});

requests[2].resolve({data: {key1: 'value1'}});
requests[3].resolve({data: {key2: 'value2'}});
requests[4].resolve({data: {key3: 'value3'}});
$rootScope.$digest();

requests[0].resolve({data: {key1: 'value1'}});
requests[1].resolve({data: {key2: 'value2'}});
$rootScope.$digest();

expect(table.key1).toEqual('value1');
expect(table.key2).toEqual('value2');
expect(table.key3).toEqual('value3');
});
});
});

});

0 comments on commit 069eafd

Please sign in to comment.