Skip to content

Commit 3a03042

Browse files
committed
chore($urlRouter): whitespace & formatting
1 parent 08b4636 commit 3a03042

File tree

1 file changed

+53
-65
lines changed

1 file changed

+53
-65
lines changed

src/urlRouter.js

Lines changed: 53 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,11 @@ function $UrlRouterProvider( $locationProvider, $urlMatcherFactory) {
6363
*
6464
* @return {object} $urlRouterProvider - $urlRouterProvider instance
6565
*/
66-
this.rule =
67-
function (rule) {
68-
if (!isFunction(rule)) throw new Error("'rule' must be a function");
69-
rules.push(rule);
70-
return this;
71-
};
66+
this.rule = function (rule) {
67+
if (!isFunction(rule)) throw new Error("'rule' must be a function");
68+
rules.push(rule);
69+
return this;
70+
};
7271

7372
/**
7473
* @ngdoc object
@@ -101,16 +100,15 @@ function $UrlRouterProvider( $locationProvider, $urlMatcherFactory) {
101100
*
102101
* @return {object} $urlRouterProvider - $urlRouterProvider instance
103102
*/
104-
this.otherwise =
105-
function (rule) {
106-
if (isString(rule)) {
107-
var redirect = rule;
108-
rule = function () { return redirect; };
109-
}
110-
else if (!isFunction(rule)) throw new Error("'rule' must be a function");
111-
otherwise = rule;
112-
return this;
113-
};
103+
this.otherwise = function (rule) {
104+
if (isString(rule)) {
105+
var redirect = rule;
106+
rule = function () { return redirect; };
107+
}
108+
else if (!isFunction(rule)) throw new Error("'rule' must be a function");
109+
otherwise = rule;
110+
return this;
111+
};
114112

115113

116114
function handleIfMatch($injector, handler, match) {
@@ -156,52 +154,49 @@ function $UrlRouterProvider( $locationProvider, $urlMatcherFactory) {
156154
* @param {string|object} what The incoming path that you want to redirect.
157155
* @param {string|object} handler The path you want to redirect your user to.
158156
*/
159-
this.when =
160-
function (what, handler) {
161-
var redirect, handlerIsString = isString(handler);
162-
if (isString(what)) what = $urlMatcherFactory.compile(what);
163-
164-
if (!handlerIsString && !isFunction(handler) && !isArray(handler))
165-
throw new Error("invalid 'handler' in when()");
157+
this.when = function (what, handler) {
158+
var redirect, handlerIsString = isString(handler);
159+
if (isString(what)) what = $urlMatcherFactory.compile(what);
166160

167-
var strategies = {
168-
matcher: function (what, handler) {
169-
if (handlerIsString) {
170-
redirect = $urlMatcherFactory.compile(handler);
171-
handler = ['$match', function ($match) { return redirect.format($match); }];
172-
}
173-
return extend(function ($injector, $location) {
174-
return handleIfMatch($injector, handler, what.exec($location.path(), $location.search()));
175-
}, {
176-
prefix: isString(what.prefix) ? what.prefix : ''
177-
});
178-
},
179-
regex: function (what, handler) {
180-
if (what.global || what.sticky) throw new Error("when() RegExp must not be global or sticky");
161+
if (!handlerIsString && !isFunction(handler) && !isArray(handler))
162+
throw new Error("invalid 'handler' in when()");
181163

182-
if (handlerIsString) {
183-
redirect = handler;
184-
handler = ['$match', function ($match) { return interpolate(redirect, $match); }];
185-
}
186-
return extend(function ($injector, $location) {
187-
return handleIfMatch($injector, handler, what.exec($location.path()));
188-
}, {
189-
prefix: regExpPrefix(what)
190-
});
164+
var strategies = {
165+
matcher: function (what, handler) {
166+
if (handlerIsString) {
167+
redirect = $urlMatcherFactory.compile(handler);
168+
handler = ['$match', function ($match) { return redirect.format($match); }];
191169
}
192-
};
193-
194-
var check = { matcher: $urlMatcherFactory.isMatcher(what), regex: what instanceof RegExp };
170+
return extend(function ($injector, $location) {
171+
return handleIfMatch($injector, handler, what.exec($location.path(), $location.search()));
172+
}, {
173+
prefix: isString(what.prefix) ? what.prefix : ''
174+
});
175+
},
176+
regex: function (what, handler) {
177+
if (what.global || what.sticky) throw new Error("when() RegExp must not be global or sticky");
195178

196-
for (var n in check) {
197-
if (check[n]) {
198-
return this.rule(strategies[n](what, handler));
179+
if (handlerIsString) {
180+
redirect = handler;
181+
handler = ['$match', function ($match) { return interpolate(redirect, $match); }];
199182
}
183+
return extend(function ($injector, $location) {
184+
return handleIfMatch($injector, handler, what.exec($location.path()));
185+
}, {
186+
prefix: regExpPrefix(what)
187+
});
200188
}
201-
202-
throw new Error("invalid 'what' in when()");
203189
};
204190

191+
var check = { matcher: $urlMatcherFactory.isMatcher(what), regex: what instanceof RegExp };
192+
193+
for (var n in check) {
194+
if (check[n]) return this.rule(strategies[n](what, handler));
195+
}
196+
197+
throw new Error("invalid 'what' in when()");
198+
};
199+
205200
/**
206201
* @ngdoc object
207202
* @name ui.router.router.$urlRouter
@@ -234,9 +229,7 @@ function $UrlRouterProvider( $locationProvider, $urlMatcherFactory) {
234229
function check(rule) {
235230
var handled = rule($injector, $location);
236231

237-
if (!handled) {
238-
return false;
239-
}
232+
if (!handled) return false;
240233
if (isString(handled)) $location.replace().url(handled);
241234
return true;
242235
}
@@ -287,20 +280,15 @@ function $UrlRouterProvider( $locationProvider, $urlMatcherFactory) {
287280
location = $location.url();
288281
return;
289282
}
290-
if ($location.url() === location) {
291-
return;
292-
}
283+
if ($location.url() === location) return;
284+
293285
$location.url(location);
294286
$location.replace();
295287
},
296288

297289
push: function(urlMatcher, params, options) {
298290
$location.url(urlMatcher.format(params));
299-
options = options || {};
300-
301-
if (options.replace) {
302-
$location.replace();
303-
}
291+
if (options && options.replace) $location.replace();
304292
},
305293

306294
href: function(urlMatcher, params, options) {

0 commit comments

Comments
 (0)