Skip to content

Commit

Permalink
Bumped version number
Browse files Browse the repository at this point in the history
  • Loading branch information
nonplus committed Oct 11, 2016
1 parent b19b5fa commit 01bcaf7
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 71 deletions.
145 changes: 76 additions & 69 deletions angular-ui-router-default.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,83 +3,90 @@
*
* @link https://github.com/nonplus/angular-ui-router-default
*
* @license angular-ui-router-default v0.0.4
* @license angular-ui-router-default v0.0.5
* (c) Copyright Stepan Riha <[email protected]>
* License MIT
*/

(function(angular) {

/* global angular */
"use strict";
var moduleName = 'ui.router.default';
if (typeof module !== "undefined" && typeof exports !== "undefined" && module.exports === exports) {
module.exports = moduleName;
}
var max_redirects = 10;
angular.module('ui.router.default', ['ui.router'])
.config(['$provide', function($provide) {
$provide.decorator('$state', ['$delegate', '$injector', '$q', function($delegate, $injector, $q) {
var transitionTo = $delegate.transitionTo;
var pendingPromise;
$delegate.transitionTo = function(to, toParams, options) {
var numRedirects = 0;
var $state = this;
var nextState = to.name || to;
var nextParams = toParams;
var nextOptions = options;
angular.module(moduleName, ['ui.router'])
.config(['$provide', function ($provide) {
$provide.decorator('$state', ['$delegate', '$injector', '$q', function ($delegate, $injector, $q) {
var transitionTo = $delegate.transitionTo;
var pendingPromise;
$delegate.transitionTo = function (to, toParams, options) {
var numRedirects = 0;
var $state = this;
var nextState = to.name || to;
var nextParams = toParams;
var nextOptions = options;
return fetchTarget();
function fetchTarget() {
var target = $state.get(nextState, $state.$current);
nextState = (target || {}).name;
var absRedirectPromise = getAbstractRedirect(target);
pendingPromise = absRedirectPromise;
return $q.when(absRedirectPromise)
.then(abstractTargetResolved);
function abstractTargetResolved(abstractTarget) {
if (absRedirectPromise !== pendingPromise) {
return $q.reject(new Error('transition superseded'));
}
// we didn't get anything from the abstract target
if (!abstractTarget) {
return transitionTo.call($delegate, nextState, nextParams, nextOptions);
}
checkForMaxRedirect();
nextState = abstractTarget;
return fetchTarget();
}
function checkForMaxRedirect() {
if (numRedirects === max_redirects) {
throw new Error('Too many abstract state default redirects');
}
numRedirects += 1;
}
}
function getAbstractRedirect(state) {
if (!state || !state.abstract || (state.abstract === true && !state.default)) {
return null;
}
return invokeAbstract(state).then(abstractInvoked);
function abstractInvoked(newState) {
if (newState[0] === '.') {
return nextState + newState;
}
else {
return newState;
}
}
}
function invokeAbstract(state) {
var defaultState;
if (state.default) {
defaultState = state.default;
}
else {
defaultState = state.abstract;
}
if (defaultState instanceof Function || defaultState instanceof Array) {
return $q.when($injector.invoke(defaultState));
}
else {
return $q.when(defaultState);
}
}
};
return $delegate;
}]);
}]);

return fetchTarget();

function fetchTarget() {
var target = $state.get(nextState, $state.$current);
nextState = (target|| {}).name;

var absRedirectPromise = getAbstractRedirect(target);
pendingPromise = absRedirectPromise;
return $q.when(absRedirectPromise, abstractTargetResolved);

function abstractTargetResolved(abstractTarget) {
if(absRedirectPromise !== pendingPromise) {
return $q.reject(new Error('transition superseded'));
}
// we didn't get anything from the abstract target
if (!abstractTarget) {
return transitionTo.call($delegate, nextState, nextParams, nextOptions);
}
checkForMaxRedirect();
nextState = abstractTarget;
return fetchTarget();
}

function checkForMaxRedirect() {
if (numRedirects === max_redirects) {
throw new Error('Too many abstract state default redirects');
}
numRedirects += 1;
}
}
function getAbstractRedirect(state) {
if (!state || !state.abstract || state.abstract === true) {
return null;
}
return invokeAbstract(state.abstract).then(abstractInvoked);
function abstractInvoked(newState) {
if (newState[0] === '.') {
return nextState + newState;
} else {
return newState;
}
}

}
function invokeAbstract(abstract) {
if (!angular.isString(abstract)) {
return $q.when($injector.invoke(abstract));
} else {
return $q.when(abstract);
}
}

};
return $delegate;
}]);
}]);

})(window.angular);
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "angular-ui-router-default",
"main": "angular-ui-router-default.js",
"version": "0.0.4",
"version": "0.0.5",
"homepage": "https://github.com/nonplus/angular-ui-router-default",
"authors": [
"Stepan Riha <[email protected]>"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-ui-router-default",
"version": "0.0.4",
"version": "0.0.5",
"description": "AngularJS module that adds support for specifying default child views for abstract states when using ui-router.",
"main": "angular-ui-router-default.js",
"types": "./index.d.ts",
Expand Down

0 comments on commit 01bcaf7

Please sign in to comment.