-
Notifications
You must be signed in to change notification settings - Fork 725
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #349 from marmelab/reference_failed
[RFR] Allow to display the listView even with missing references
- Loading branch information
Showing
10 changed files
with
276 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/*global define*/ | ||
define(function () { | ||
'use strict'; | ||
|
||
function PromisesResolver($q) { | ||
|
||
function allEvenFailed(promises) { | ||
if (!Array.isArray(promises)) { | ||
throw 'allEvenFailed can only handle an array of promises'; | ||
} | ||
var deferred = $q.defer(); | ||
if (promises.length === 0) { | ||
deferred.resolve([]); | ||
return deferred.promise; | ||
} | ||
|
||
var states = []; | ||
var results = []; | ||
|
||
promises.forEach(function (promise, key) { | ||
states[key] = false; // promises are not resolved by default | ||
}); | ||
|
||
promises.forEach(function (promise, key) { | ||
function resolve(result) { | ||
states[key] = true; | ||
results[key] = result; // result may be an error | ||
for (var i in states) { | ||
if (!states[i]) { | ||
return; | ||
} | ||
} | ||
deferred.resolve(results); | ||
} | ||
function resolveSuccess(result) { | ||
return resolve({ status: 'success', result: result }); | ||
} | ||
function resolveError(result) { | ||
return resolve({ status: 'error', error: result }) | ||
} | ||
// whether the promise ends with success or error, consider it done | ||
$q.when(promise).then(resolveSuccess, resolveError); | ||
}); | ||
|
||
return deferred.promise; | ||
}; | ||
|
||
return { | ||
allEvenFailed: allEvenFailed | ||
}; | ||
} | ||
|
||
PromisesResolver.$inject = ['$q']; | ||
|
||
return PromisesResolver; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/*global jasmine,define*/ | ||
|
||
define('mock/PromisesResolver', ['mixins'], function (mixins) { | ||
"use strict"; | ||
|
||
return { | ||
allEvenFailed: function() { return mixins.buildPromise([]); } | ||
}; | ||
}); |
Oops, something went wrong.