From 639e0565dece9d5544cc93b3eee6e11c99bd7373 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ce=CC=81sar=20Andreu?= Date: Thu, 4 Sep 2014 14:19:17 -0700 Subject: [PATCH] feat($state): .reload() returns state transition promise You could want to perform an action after a state is reloaded Since .reload() is a shortcut for .transitionTo(), it makes sense to pass on the promise --- src/state.js | 5 ++++- test/stateSpec.js | 10 ++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/state.js b/src/state.js index c70946046..3330a8655 100644 --- a/src/state.js +++ b/src/state.js @@ -644,9 +644,12 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) { * reload: true, inherit: false, notify: false * }); * + * + * @returns {promise} A promise representing the state of the new transition. See + * {@link ui.router.state.$state#methods_go $state.go}. */ $state.reload = function reload() { - $state.transitionTo($state.current, $stateParams, { reload: true, inherit: false, notify: false }); + return $state.transitionTo($state.current, $stateParams, { reload: true, inherit: false, notify: false }); }; /** diff --git a/test/stateSpec.js b/test/stateSpec.js index 0c4d6bb6f..65a8c04b3 100644 --- a/test/stateSpec.js +++ b/test/stateSpec.js @@ -487,6 +487,16 @@ describe('state', function () { }); describe('.reload()', function () { + it('returns a promise for the state transition', inject(function ($state, $q) { + var trans = $state.transitionTo(A, {}); + $q.flush(); + expect(resolvedValue(trans)).toBe(A); + + trans = $state.reload(); + $q.flush(); + expect(resolvedValue(trans)).toBe(A); + })); + it('should reload the current state with the current parameters', inject(function ($state, $q, $timeout) { $state.transitionTo('resolveTimeout', { foo: "bar" }); $q.flush();