ui-router-extras
ui-router-extras copied to clipboard
Make $futureStateProvider.futureState() chainable
This is a feature request, not a bug.
Could you make $futureStateProvider.futureState() chainable by returning the $futureStateProvider from the futureState method? For example:
this.futureState = function (futureState) {
if (futureState.stateName) // backwards compat for now
futureState.name = futureState.stateName;
if (futureState.urlPrefix) // backwards compat for now
futureState.url = "^" + futureState.urlPrefix;
futureStates[futureState.name] = futureState;
var parentMatcher, parentName = futureState.name.split(/\./).slice(0, -1).join("."),
realParent = findState(futureState.parent || parentName);
if (realParent) {
parentMatcher = realParent.url || realParent.navigable && realParent.navigable.url;
} else if (parentName === "") {
parentMatcher = $urlMatcherFactory.compile("");
} else {
var futureParent = findState((futureState.parent || parentName), true);
if (!futureParent) throw new Error("Couldn't determine parent state of future state. FutureState:" + angular.toJson(futureState));
var pattern;
if (futureParent.urlMatcher) {
pattern = futureParent.urlMatcher.source.replace(/\*rest$/, "");
}
else {
// if the futureParent doesn't have a urlMatcher, then we are still
// starting from the beginning of the path
pattern = "";
}
parentMatcher = $urlMatcherFactory.compile(pattern);
futureState.parentFutureState = futureParent;
}
if (futureState.url) {
futureState.urlMatcher = futureState.url.charAt(0) === "^" ?
$urlMatcherFactory.compile(futureState.url.substring(1) + "*rest") :
parentMatcher.concat(futureState.url + "*rest");
}
return provider; // return instance of provider to support method chaining
};
PR welcomed.