Skip to content
This repository has been archived by the owner on Sep 20, 2020. It is now read-only.

Commit

Permalink
fix(sticky): fix sticky state registration
Browse files Browse the repository at this point in the history
 - made sticky state registration use core.js onStateRegistered.
  • Loading branch information
christopherthielen committed Jan 27, 2015
1 parent 07cb588 commit d84311e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 24 deletions.
17 changes: 5 additions & 12 deletions src/core.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var mod_core = angular.module("ct.ui.router.extras.core", [ "ui.router" ]);

var internalStates = {};
var internalStates = {}, stateRegisteredCallbacks = [];
mod_core.config([ '$stateProvider', '$injector', function ($stateProvider, $injector) {
// Decorate any state attribute in order to get access to the internal state representation.
$stateProvider.decorator('parent', function (state, parentFn) {
Expand All @@ -12,17 +12,7 @@ mod_core.config([ '$stateProvider', '$injector', function ($stateProvider, $inje
return internalStates[state.self.name];
};

try {
var $stickyStateProvider = $injector.get('$stickyStateProvider');
// Register the ones marked as "sticky" if sticky module is included.
if ($stickyStateProvider && state.self.sticky === true) {
$stickyStateProvider.registerStickyState(state.self);
// console.log("ok, registered sticky state");
}
} catch (error) {
// ignore; sticky state module isn't available.
}

angular.forEach(stateRegisteredCallbacks, function(callback) { callback(state); });
return parentFn(state);
});
}]);
Expand Down Expand Up @@ -150,9 +140,12 @@ function inherit(parent, extra) {
return extend(new (extend(function () { }, {prototype: parent}))(), extra);
}

function onStateRegistered(callback) { stateRegisteredCallbacks.push(callback); }

mod_core.provider("uirextras_core", function() {
var core = {
internalStates: internalStates,
onStateRegistered: onStateRegistered,
forEach: forEach,
extend: extend,
isArray: isArray,
Expand Down
13 changes: 1 addition & 12 deletions src/sticky.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,22 +99,11 @@ angular.module("ct.ui.router.extras.sticky").config(
root = pendingRestore = undefined;
pendingTransitions = [];

// Decorate any state attribute in order to get access to the internal state representation.
$stateProvider.decorator('parent', function (state, parentFn) {
// Capture each internal UI-Router state representations as opposed to the user-defined state object.
// The internal state is, e.g., the state returned by $state.$current as opposed to $state.current
internalStates[state.self.name] = state;
// Add an accessor for the internal state from the user defined state
state.self.$$state = function () {
return internalStates[state.self.name];
};

uirextras_coreProvider.onStateRegistered(function(state) {
// Register the ones marked as "sticky"
if (state.self.sticky === true) {
$stickyStateProvider.registerStickyState(state.self);
}

return parentFn(state);
});

var $state_transitionTo; // internal reference to the real $state.transitionTo function
Expand Down

0 comments on commit d84311e

Please sign in to comment.