Skip to content

Commit 0e94f91

Browse files
committed
fix(loader): make the loader service return a promise instead of the deprecated object, update docum
make the loader service return a promise instead of the deprecated object, update documents to show proper usage #3717
1 parent 71ff999 commit 0e94f91

File tree

2 files changed

+17
-30
lines changed

2 files changed

+17
-30
lines changed

Diff for: js/angular/service/loading.js

+17-29
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ var LOADING_TPL =
55
'</div>' +
66
'</div>';
77

8-
var LOADING_HIDE_DEPRECATED = '$ionicLoading instance.hide() has been deprecated. Use $ionicLoading.hide().';
9-
var LOADING_SHOW_DEPRECATED = '$ionicLoading instance.show() has been deprecated. Use $ionicLoading.show().';
10-
var LOADING_SET_DEPRECATED = '$ionicLoading instance.setContent() has been deprecated. Use $ionicLoading.show({ template: \'my content\' }).';
11-
128
/**
139
* @ngdoc service
1410
* @name $ionicLoading
@@ -24,10 +20,14 @@ var LOADING_SET_DEPRECATED = '$ionicLoading instance.setContent() has been depre
2420
* $scope.show = function() {
2521
* $ionicLoading.show({
2622
* template: 'Loading...'
23+
* }).then(function(){
24+
* console.log("The loading indicator is now displayed");
2725
* });
2826
* };
2927
* $scope.hide = function(){
30-
* $ionicLoading.hide();
28+
* $ionicLoading.hide().then(function(){
29+
* console.log("The loading indicator is now hidden");
30+
* });
3131
* };
3232
* });
3333
* ```
@@ -47,7 +47,10 @@ var LOADING_SET_DEPRECATED = '$ionicLoading instance.setContent() has been depre
4747
* });
4848
* app.controller('AppCtrl', function($scope, $ionicLoading) {
4949
* $scope.showLoading = function() {
50-
* $ionicLoading.show(); //options default to values in $ionicLoadingConfig
50+
* //options default to values in $ionicLoadingConfig
51+
* $ionicLoading.show().then(function(){
52+
* console.log("The loading indicator is now displayed");
53+
* });
5154
* };
5255
* });
5356
* ```
@@ -82,9 +85,8 @@ function($ionicLoadingConfig, $ionicBody, $ionicTemplateLoader, $ionicBackdrop,
8285
* @ngdoc method
8386
* @name $ionicLoading#show
8487
* @description Shows a loading indicator. If the indicator is already shown,
85-
* it will set the options given and keep the indicator shown. Note: While this
86-
* function still returns an $ionicLoading instance for backwards compatiblity,
87-
* its use has been deprecated.
88+
* it will set the options given and keep the indicator shown.
89+
* @returns {promise} A promise which is resolved when the loading indicator is presented.
8890
* @param {object} opts The options for the loading indicator. Available properties:
8991
* - `{string=}` `template` The html content of the indicator.
9092
* - `{string=}` `templateUrl` The url of an html template to load as the content of the indicator.
@@ -101,6 +103,7 @@ function($ionicLoadingConfig, $ionicBody, $ionicTemplateLoader, $ionicBackdrop,
101103
* @ngdoc method
102104
* @name $ionicLoading#hide
103105
* @description Hides the loading indicator, if shown.
106+
* @returns {promise} A promise which is resolved when the loading indicator is hidden.
104107
*/
105108
hide: hideLoader,
106109
/**
@@ -198,6 +201,8 @@ function($ionicLoadingConfig, $ionicBody, $ionicTemplateLoader, $ionicBackdrop,
198201

199202
function showLoader(options) {
200203
options = extend({}, $ionicLoadingConfig || {}, options || {});
204+
// use a default delay of 100 to avoid some issues reported on github
205+
// https://github.com/driftyco/ionic/issues/3717
201206
var delay = options.delay || options.showDelay || 0;
202207

203208
deregisterStateListener1();
@@ -210,34 +215,17 @@ function($ionicLoadingConfig, $ionicBody, $ionicTemplateLoader, $ionicBackdrop,
210215
//If loading.show() was called previously, cancel it and show with our new options
211216
$timeout.cancel(loadingShowDelay);
212217
loadingShowDelay = $timeout(noop, delay);
213-
loadingShowDelay.then(getLoader).then(function(loader) {
218+
return loadingShowDelay.then(getLoader).then(function(loader) {
214219
return loader.show(options);
215220
});
216-
217-
return {
218-
hide: function deprecatedHide() {
219-
$log.error(LOADING_HIDE_DEPRECATED);
220-
return hideLoader.apply(this, arguments);
221-
},
222-
show: function deprecatedShow() {
223-
$log.error(LOADING_SHOW_DEPRECATED);
224-
return showLoader.apply(this, arguments);
225-
},
226-
setContent: function deprecatedSetContent(content) {
227-
$log.error(LOADING_SET_DEPRECATED);
228-
return getLoader().then(function(loader) {
229-
loader.show({ template: content });
230-
});
231-
}
232-
};
233221
}
234222

235223
function hideLoader() {
236224
deregisterStateListener1();
237225
deregisterStateListener2();
238226
$timeout.cancel(loadingShowDelay);
239-
getLoader().then(function(loader) {
240-
loader.hide();
227+
return getLoader().then(function(loader) {
228+
return loader.hide();
241229
});
242230
}
243231
}]);

Diff for: test/unit/angular/service/loading.unit.js

-1
Original file line numberDiff line numberDiff line change
@@ -254,4 +254,3 @@ describe('$ionicLoadingConfig', function() {
254254
}));
255255

256256
});
257-

0 commit comments

Comments
 (0)