Skip to content

Commit

Permalink
fix(Param): fix default value shorthand declaration
Browse files Browse the repository at this point in the history
Closes #1554
  • Loading branch information
christopherthielen committed Nov 17, 2014
1 parent 74aa609 commit 831d812
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions src/urlMatcherFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -864,27 +864,23 @@ function $UrlMatcherFactory() {

this.Param = function Param(id, type, config, location) {
var self = this;
var defaultValueConfig = getDefaultValueConfig(config);
config = config || {};
config = unwrapShorthand(config);
type = getType(config, type);
var arrayMode = getArrayMode();
type = arrayMode ? type.$asArray(arrayMode, location === "search") : type;
if (type.name === "string" && !arrayMode && location === "path" && defaultValueConfig.value === undefined)
defaultValueConfig.value = ""; // for 0.2.x; in 0.3.0+ do not automatically default to ""
var isOptional = defaultValueConfig.value !== undefined;
if (type.name === "string" && !arrayMode && location === "path" && config.value === undefined)
config.value = ""; // for 0.2.x; in 0.3.0+ do not automatically default to ""
var isOptional = config.value !== undefined;
var squash = getSquashPolicy(config, isOptional);
var replace = getReplace(config, arrayMode, isOptional, squash);

function getDefaultValueConfig(config) {
function unwrapShorthand(config) {
var keys = isObject(config) ? objectKeys(config) : [];
var isShorthand = indexOf(keys, "value") === -1 && indexOf(keys, "type") === -1 &&
indexOf(keys, "squash") === -1 && indexOf(keys, "array") === -1;
var configValue = isShorthand ? config : config.value;
var result = {
fn: isInjectable(configValue) ? configValue : function () { return result.value; },
value: configValue
};
return result;
if (isShorthand) config = { value: config };
config.$$fn = isInjectable(config.value) ? config.value : function () { return config.value; };
return config;
}

function getType(config, urlType) {
Expand Down Expand Up @@ -929,7 +925,7 @@ function $UrlMatcherFactory() {
*/
function $$getDefaultValue() {
if (!injector) throw new Error("Injectable functions cannot be called at configuration time");
return injector.invoke(defaultValueConfig.fn);
return injector.invoke(config.$$fn);
}

/**
Expand Down

0 comments on commit 831d812

Please sign in to comment.