All transaction-based ControlService methods now return promises directly, which makes it easier to integrate with other promises, is simpler and opens up new refactoring opportunities.

This commit is contained in:
Simo Kinnunen
2014-04-15 16:56:13 +09:00
parent 4270d9589c
commit f46540e51e
5 changed files with 23 additions and 29 deletions

View File

@@ -16,9 +16,8 @@ module.exports = function UploadCtrl($scope, SettingsService, gettext) {
lastData: 'uploading'
}
var upload = $scope.control.uploadUrl(url)
$scope.installation = null
return upload.promise
return $scope.control.uploadUrl(url)
.progressed(function (uploadResult) {
$scope.$apply(function () {
$scope.upload = uploadResult
@@ -40,9 +39,8 @@ module.exports = function UploadCtrl($scope, SettingsService, gettext) {
lastData: 'uploading'
}
var upload = $scope.control.uploadFile($files)
$scope.installation = null
return upload.promise
return $scope.control.uploadFile($files)
.progressed(function (uploadResult) {
$scope.$apply(function () {
$scope.upload = uploadResult
@@ -60,8 +58,7 @@ module.exports = function UploadCtrl($scope, SettingsService, gettext) {
$scope.maybeInstall = function (options) {
if ($scope.installEnabled) {
var install = $scope.control.install(options)
return install.promise
return $scope.control.install(options)
.progressed(function (installResult) {
$scope.$apply(function () {
installResult.manifest = options.manifest
@@ -79,16 +76,16 @@ module.exports = function UploadCtrl($scope, SettingsService, gettext) {
}
$scope.uninstall = function (packageName) {
var tx = $scope.control.uninstall(packageName)
return tx.promise.then(function (result) {
if (result.success) {
$scope.$apply(function () {
$scope.clear()
})
} else {
console.error(result.error)
}
})
return $scope.control.uninstall(packageName)
.then(function (result) {
if (result.success) {
$scope.$apply(function () {
$scope.clear()
})
} else {
console.error(result.error)
}
})
}
$scope.taskFinished = function () {