Skip to content

Commit 4239ed8

Browse files
committed
initial stab at testing $state.transitionTo() and related promises (see #41)
1 parent 8648848 commit 4239ed8

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

src/stateProvider.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
113113
views: null,
114114
abstract: true
115115
});
116-
root.locals = {};
116+
root.locals = { globals: { $stateParams: {} } };
117+
root.navigable = null;
117118

118119

119120
// .state(state)
@@ -135,8 +136,11 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
135136
params: {},
136137
current: root.self,
137138
$current: root,
139+
140+
transition: null,
138141
$transition: $q.when(root.self),
139142

143+
140144
transitionTo: transitionTo,
141145

142146
is: function (stateOrName) {
@@ -181,15 +185,15 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
181185
// (fully resolved) current locals, and pass this down the chain.
182186
var resolved = $q.when(locals);
183187
for (var l=keep; l<toPath.length; l++, state=toPath[l]) {
184-
locals = toLocals[l] = (locals ? inherit(locals) : {});
188+
locals = toLocals[l] = inherit(locals);
185189
resolved = resolveState(state, toParams, resolved, locals);
186190
}
187191

188192
// Once everything is resolved, we are ready to perform the actual transition
189193
// and return a promise for the new state. We also keep track of what the
190194
// current promise is, so that we can detect overlapping transitions and
191195
// keep only the outcome of the last transition.
192-
var transition = $state.transition = resolved.then(function () {
196+
var transition = $state.transition = $state.$transition = resolved.then(function () {
193197
var l, entering, exiting;
194198

195199
if ($state.transition !== transition) return; // superseded by a new transition
@@ -218,6 +222,7 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
218222
$state.current = to.self;
219223
$state.params = locals.globals.$stateParams; // these are normalized, unlike toParams
220224
copy($state.params, $stateParams);
225+
$state.transition = null;
221226

222227
// Update $location
223228
var toNav = to.navigable;
@@ -226,9 +231,13 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
226231
}
227232

228233
$rootScope.$broadcast('$stateChangeSuccess', to.self, from.self);
234+
229235
return $state.current;
230236
}, function (error) {
231237
if ($state.transition !== transition) return; // superseded by a new transition
238+
239+
$state.transition = null;
240+
232241
$rootScope.$broadcast('$stateChangeError', to.self, from.self, error);
233242
return $q.reject(error);
234243
});

test/stateProviderSpec.js

Whitespace-only changes.

test/test-config.js

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ files = [
99
JASMINE_ADAPTER,
1010
'lib/angular-1.0.4.js',
1111
'test/lib/angular-mocks-1.0.4.js',
12+
'test/testUtils.js',
1213
'src/*.js',
1314
'test/*Spec.js',
1415
];

test/urlRouteProviderSpec.js

Whitespace-only changes.

0 commit comments

Comments
 (0)