Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code refactoring for ember-routing package #14821

Merged
merged 4 commits into from
Jan 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/ember-routing/lib/ext/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ ControllerMixin.reopen({
@method _qpChanged
@private
*/
_qpChanged(controller, _prop) {
let prop = _prop.substr(0, _prop.length - 3);
_qpChanged(controller, prop) {
prop = prop.substr(0, prop.length - 3);

let delegate = controller._qpDelegate;
let value = get(controller, prop);
Expand Down
14 changes: 7 additions & 7 deletions packages/ember-routing/lib/location/auto_location.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export default EmberObject.extend({
location: this.location,
history: this.history,
userAgent: this.userAgent,
rootURL: rootURL,
rootURL,
documentMode: this.documentMode,
global: this.global
});
Expand Down Expand Up @@ -255,18 +255,18 @@ export function getHistoryPath(rootURL, location) {

// If the path already has a trailing slash, remove the one
// from the hashed route so we don't double up.
if (path.slice(-1) === '/') {
if (path.charAt(path.length - 1) === '/') {
routeHash = routeHash.substr(1);
}

// This is the "expected" final order
path = path + routeHash + query;
path += routeHash + query;

if (hashParts.length) {
path += `#${hashParts.join('#')}`;
}
} else {
path = path + query + hash;
path += query + hash;
}

return path;
Expand All @@ -286,11 +286,11 @@ export function getHashPath(rootURL, location) {
let routePath = historyPath.substr(rootURL.length);

if (routePath !== '') {
if (routePath.charAt(0) !== '/') {
routePath = '/' + routePath;
if (routePath[0] !== '/') {
routePath = `/${routePath}`;
}

path += '#' + routePath;
path += `#${routePath}`;
}

return path;
Expand Down
2 changes: 1 addition & 1 deletion packages/ember-routing/lib/location/hash_location.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export default EmberObject.extend({
let originalPath = this.getHash().substr(1);
let outPath = originalPath;

if (outPath.charAt(0) !== '/') {
if (outPath[0] !== '/') {
outPath = '/';

// Only add the # if the path isn't empty.
Expand Down
18 changes: 10 additions & 8 deletions packages/ember-routing/lib/location/history_location.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ export default EmberObject.extend({
this._super(...arguments);

let base = document.querySelector('base');
let baseURL = base ? base.getAttribute('href') : '';
let baseURL = '';
if (base) {
baseURL = base.getAttribute('href');
}

set(this, 'baseURL', baseURL);
set(this, 'location', get(this, 'location') || window.location);
Expand Down Expand Up @@ -83,12 +86,11 @@ export default EmberObject.extend({

// remove baseURL and rootURL from start of path
let url = path
.replace(new RegExp('^' + baseURL + '(?=/|$)'), '')
.replace(new RegExp('^' + rootURL + '(?=/|$)'), '');
.replace(new RegExp(`^${baseURL}(?=/|$)`), '')
.replace(new RegExp(`^${rootURL}(?=/|$)`), '');

let search = location.search || '';
url += search;
url += this.getHash();
url += search + this.getHash();

return url;
},
Expand Down Expand Up @@ -152,7 +154,7 @@ export default EmberObject.extend({
@param path {String}
*/
pushState(path) {
let state = { path: path };
let state = { path };

get(this, 'history').pushState(state, null, path);

Expand All @@ -170,7 +172,7 @@ export default EmberObject.extend({
@param path {String}
*/
replaceState(path) {
let state = { path: path };
let state = { path };
get(this, 'history').replaceState(state, null, path);

this._historyState = state;
Expand Down Expand Up @@ -218,7 +220,7 @@ export default EmberObject.extend({
// remove trailing slashes if they exists
rootURL = rootURL.replace(/\/$/, '');
baseURL = baseURL.replace(/\/$/, '');
} else if (baseURL.match(/^\//) && rootURL.match(/^\//)) {
} else if (baseURL[0] === '/' && rootURL[0] === '/') {
// if baseURL and rootURL both start with a slash
// ... remove trailing slash from baseURL if it exists
baseURL = baseURL.replace(/\/$/, '');
Expand Down
2 changes: 1 addition & 1 deletion packages/ember-routing/lib/location/none_location.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export default EmberObject.extend({
rootURL = rootURL.replace(/\/$/, '');

// remove rootURL from url
return path.replace(new RegExp('^' + rootURL + '(?=/|$)'), '');
return path.replace(new RegExp(`^${rootURL}(?=/|$)`), '');
},

/**
Expand Down
12 changes: 6 additions & 6 deletions packages/ember-routing/lib/location/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
Returns the current `location.pathname`, normalized for IE inconsistencies.
*/
export function getPath(location) {
var pathname = location.pathname;
let pathname = location.pathname;
// Various versions of IE/Opera don't always return a leading slash
if (pathname.charAt(0) !== '/') {
if (pathname[0] !== '/') {
pathname = `/${pathname}`;
}

Expand All @@ -33,8 +33,8 @@ export function getQuery(location) {
https://bugzilla.mozilla.org/show_bug.cgi?id=483304
*/
export function getHash(location) {
var href = location.href;
var hashIndex = href.indexOf('#');
let href = location.href;
let hashIndex = href.indexOf('#');

if (hashIndex === -1) {
return '';
Expand All @@ -48,11 +48,11 @@ export function getFullPath(location) {
}

export function getOrigin(location) {
var origin = location.origin;
let origin = location.origin;

// Older browsers, especially IE, don't have origin
if (!origin) {
origin = location.protocol + '//' + location.hostname;
origin = `${location.protocol}//${location.hostname}`;

if (location.port) {
origin += `:${location.port}`;
Expand Down
4 changes: 2 additions & 2 deletions packages/ember-routing/lib/services/routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default Service.extend({
this.normalizeQueryParams(routeName, models, visibleQueryParams);

let args = routeArgs(routeName, models, visibleQueryParams);
return router.generate.apply(router, args);
return router.generate(...args);
},

isActiveForRoute(contexts, queryParams, routeName, routerState, isCurrentWhenSpecified) {
Expand Down Expand Up @@ -97,7 +97,7 @@ export default Service.extend({
function numberOfContextsAcceptedByHandler(handler, handlerInfos) {
let req = 0;
for (let i = 0; i < handlerInfos.length; i++) {
req = req + handlerInfos[i].names.length;
req += handlerInfos[i].names.length;
if (handlerInfos[i].handler === handler) {
break;
}
Expand Down
Loading