Skip to content

Commit

Permalink
fix($state): do not emit $viewContentLoading if notify: false
Browse files Browse the repository at this point in the history
 - pass options.notify to $view.load() from $state.go(), i.e.:
   $state.go($state.current.name, { }, { notify: false})
 Closes #1387
  • Loading branch information
christopherthielen committed Oct 21, 2014
1 parent 4533fe3 commit 74255fe
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,7 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {

for (var l = keep; l < toPath.length; l++, state = toPath[l]) {
locals = toLocals[l] = inherit(locals);
resolved = resolveState(state, toParams, state === to, resolved, locals);
resolved = resolveState(state, toParams, state === to, resolved, locals, options);
}

// Once everything is resolved, we are ready to perform the actual transition
Expand Down Expand Up @@ -1149,7 +1149,7 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
return (state && state.self) ? state.self : null;
};

function resolveState(state, params, paramsAreFiltered, inherited, dst) {
function resolveState(state, params, paramsAreFiltered, inherited, dst, options) {
// Make a restricted $stateParams with only the parameters that apply to this state if
// necessary. In addition to being available to the controller and onEnter/onExit callbacks,
// we also need $stateParams to be available for any $injector calls we make during the
Expand All @@ -1171,7 +1171,7 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
forEach(state.views, function (view, name) {
var injectables = (view.resolve && view.resolve !== state.resolve ? view.resolve : {});
injectables.$template = [ function () {
return $view.load(name, { view: view, locals: locals, params: $stateParams }) || '';
return $view.load(name, { view: view, locals: locals, params: $stateParams, notify: options.notify }) || '';
}];

promises.push($resolve.resolve(injectables, locals, dst.resolve, state).then(function (result) {
Expand Down
19 changes: 9 additions & 10 deletions test/stateSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ describe('state', function () {
C = {},
D = { params: { x: null, y: null } },
DD = { parent: D, params: { x: null, y: null, z: null } },
DDDD = { parent: D, controller: function() {}, template: "hey"},
E = { params: { i: {} } },
H = { data: {propA: 'propA', propB: 'propB'} },
HH = { parent: H },
Expand All @@ -44,6 +45,7 @@ describe('state', function () {
.state('C', C)
.state('D', D)
.state('DD', DD)
.state('DDDD', DDDD)
.state('E', E)
.state('H', H)
.state('HH', HH)
Expand Down Expand Up @@ -332,28 +334,24 @@ describe('state', function () {
expect($state.current).toBe(D);
}));

it('does not trigger $stateChangeSuccess when suppressed, but changes state', inject(function ($state, $q, $rootScope) {
it('does not trigger $stateChangeSuccess or $viewContentLoading when suppressed, but changes state', inject(function ($state, $q, $rootScope, $httpBackend) {
initStateTo(E, { i: 'iii' });
var called;

$rootScope.$on('$stateChangeSuccess', function (ev, to, toParams, from, fromParams) {
called = true;
});

$state.transitionTo(D, { x: '1', y: '2' }, { notify: false });
$rootScope.$on('$stateChangeSuccess', function () { called = true; });
$rootScope.$on('$viewContentLoading', function (evt, foo) { called = true; });
$state.transitionTo(DDDD, {}, { notify: false });
$q.flush();

expect(called).toBeFalsy();
expect($state.current).toBe(D);
expect($state.current).toBe(DDDD);
}));

it('does not trigger $stateChangeSuccess when suppressed, but updates params', inject(function ($state, $q, $rootScope) {
initStateTo(E, { x: 'iii' });
var called;

$rootScope.$on('$stateChangeSuccess', function (ev, to, toParams, from, fromParams) {
called = true;
});
$rootScope.$on('$stateChangeSuccess', function () { called = true; });
$state.transitionTo(E, { i: '1', y: '2' }, { notify: false });
$q.flush();

Expand Down Expand Up @@ -748,6 +746,7 @@ describe('state', function () {
'C',
'D',
'DD',
'DDDD',
'E',
'H',
'HH',
Expand Down

0 comments on commit 74255fe

Please sign in to comment.