Skip to content

Commit b80d66f

Browse files
committed
Merge pull request #10637 from chadhietala/6-to-5
Arrow functions, rest params, and template literals in routing and extension support
2 parents 8e8b332 + 5503b57 commit b80d66f

13 files changed

+110
-125
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"ember-cli-dependency-checker": "0.0.7",
1919
"ember-cli-yuidoc": "^0.4.0",
2020
"ember-publisher": "0.0.7",
21-
"emberjs-build": "0.0.43",
21+
"emberjs-build": "0.0.44",
2222
"esperanto": "0.6.17",
2323
"express": "^4.5.0",
2424
"github": "^0.2.3",

packages/ember-extension-support/lib/container_debug_adapter.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export default EmberObject.extend({
9494
catalogEntriesByType(type) {
9595
var namespaces = emberA(Namespace.NAMESPACES);
9696
var types = emberA();
97-
var typeSuffixRegex = new RegExp(classify(type) + "$");
97+
var typeSuffixRegex = new RegExp(`${classify(type)}$`);
9898

9999
namespaces.forEach(function(namespace) {
100100
if (namespace !== Ember) {

packages/ember-extension-support/lib/data_adapter.js

+28-33
Original file line numberDiff line numberDiff line change
@@ -132,30 +132,29 @@ export default EmberObject.extend({
132132
*/
133133
watchModelTypes(typesAdded, typesUpdated) {
134134
var modelTypes = this.getModelTypes();
135-
var self = this;
136135
var releaseMethods = emberA();
137136
var typesToSend;
138137

139-
typesToSend = modelTypes.map(function(type) {
138+
typesToSend = modelTypes.map((type) => {
140139
var klass = type.klass;
141-
var wrapped = self.wrapModelType(klass, type.name);
142-
releaseMethods.push(self.observeModelType(klass, typesUpdated));
140+
var wrapped = this.wrapModelType(klass, type.name);
141+
releaseMethods.push(this.observeModelType(klass, typesUpdated));
143142
return wrapped;
144143
});
145144

146145
typesAdded(typesToSend);
147146

148-
var release = function() {
149-
releaseMethods.forEach(function(fn) { fn(); });
150-
self.releaseMethods.removeObject(release);
147+
var release = () => {
148+
releaseMethods.forEach((fn) => fn() );
149+
this.releaseMethods.removeObject(release);
151150
};
152151
this.releaseMethods.pushObject(release);
153152
return release;
154153
},
155154

156155
_nameToClass(type) {
157156
if (typeof type === 'string') {
158-
type = this.container.lookupFactory('model:' + type);
157+
type = this.container.lookupFactory(`model:${type}`);
159158
}
160159
return type;
161160
},
@@ -183,7 +182,6 @@ export default EmberObject.extend({
183182
@return {Function} Method to call to remove all observers
184183
*/
185184
watchRecords(type, recordsAdded, recordsUpdated, recordsRemoved) {
186-
var self = this;
187185
var releaseMethods = emberA();
188186
var records = this.getRecords(type);
189187
var release;
@@ -192,17 +190,17 @@ export default EmberObject.extend({
192190
recordsUpdated([updatedRecord]);
193191
};
194192

195-
var recordsToSend = records.map(function(record) {
196-
releaseMethods.push(self.observeRecord(record, recordUpdated));
197-
return self.wrapRecord(record);
193+
var recordsToSend = records.map((record) => {
194+
releaseMethods.push(this.observeRecord(record, recordUpdated));
195+
return this.wrapRecord(record);
198196
});
199197

200198

201-
var contentDidChange = function(array, idx, removedCount, addedCount) {
199+
var contentDidChange = (array, idx, removedCount, addedCount) => {
202200
for (var i = idx; i < idx + addedCount; i++) {
203201
var record = array.objectAt(i);
204-
var wrapped = self.wrapRecord(record);
205-
releaseMethods.push(self.observeRecord(record, recordUpdated));
202+
var wrapped = this.wrapRecord(record);
203+
releaseMethods.push(this.observeRecord(record, recordUpdated));
206204
recordsAdded([wrapped]);
207205
}
208206

@@ -212,12 +210,12 @@ export default EmberObject.extend({
212210
};
213211

214212
var observer = { didChange: contentDidChange, willChange() { return this; } };
215-
records.addArrayObserver(self, observer);
213+
records.addArrayObserver(this, observer);
216214

217-
release = function() {
215+
release = () => {
218216
releaseMethods.forEach(function(fn) { fn(); });
219-
records.removeArrayObserver(self, observer);
220-
self.releaseMethods.removeObject(release);
217+
records.removeArrayObserver(this, observer);
218+
this.releaseMethods.removeObject(release);
221219
};
222220

223221
recordsAdded(recordsToSend);
@@ -278,11 +276,10 @@ export default EmberObject.extend({
278276
*/
279277

280278
observeModelType(type, typesUpdated) {
281-
var self = this;
282279
var records = this.getRecords(type);
283280

284-
var onChange = function() {
285-
typesUpdated([self.wrapModelType(type)]);
281+
var onChange = () => {
282+
typesUpdated([this.wrapModelType(type)]);
286283
};
287284
var observer = {
288285
didChange() {
@@ -293,8 +290,8 @@ export default EmberObject.extend({
293290

294291
records.addArrayObserver(this, observer);
295292

296-
var release = function() {
297-
records.removeArrayObserver(self, observer);
293+
var release = () => {
294+
records.removeArrayObserver(this, observer);
298295
};
299296

300297
return release;
@@ -342,7 +339,6 @@ export default EmberObject.extend({
342339
@return {Array} Array of model types
343340
*/
344341
getModelTypes() {
345-
var self = this;
346342
var containerDebugAdapter = this.get('containerDebugAdapter');
347343
var types;
348344

@@ -353,14 +349,14 @@ export default EmberObject.extend({
353349
}
354350

355351
// New adapters return strings instead of classes
356-
types = emberA(types).map(function(name) {
352+
types = emberA(types).map((name) => {
357353
return {
358-
klass: self._nameToClass(name),
354+
klass: this._nameToClass(name),
359355
name: name
360356
};
361357
});
362-
types = emberA(types).filter(function(type) {
363-
return self.detect(type.klass);
358+
types = emberA(types).filter((type) => {
359+
return this.detect(type.klass);
364360
});
365361

366362
return emberA(types);
@@ -377,18 +373,17 @@ export default EmberObject.extend({
377373
_getObjectsOnNamespaces() {
378374
var namespaces = emberA(Namespace.NAMESPACES);
379375
var types = emberA();
380-
var self = this;
381376

382-
namespaces.forEach(function(namespace) {
377+
namespaces.forEach((namespace) => {
383378
for (var key in namespace) {
384379
if (!namespace.hasOwnProperty(key)) { continue; }
385380
// Even though we will filter again in `getModelTypes`,
386381
// we should not call `lookupContainer` on non-models
387382
// (especially when `Ember.MODEL_FACTORY_INJECTIONS` is `true`)
388-
if (!self.detect(namespace[key])) { continue; }
383+
if (!this.detect(namespace[key])) { continue; }
389384
var name = dasherize(key);
390385
if (!(namespace instanceof Application) && namespace.toString()) {
391-
name = namespace + '/' + name;
386+
name = `${namespace}/${name}`;
392387
}
393388
types.push(name);
394389
}

packages/ember-routing/lib/location/api.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ export default {
149149
Ember.assert("Ember.Location.create: you must specify a 'implementation' option", !!implementation);
150150

151151
var implementationClass = this.implementations[implementation];
152-
Ember.assert("Ember.Location.create: " + implementation + " is not a valid implementation", !!implementationClass);
152+
Ember.assert(`Ember.Location.create: ${implementation} is not a valid implementation`, !!implementationClass);
153153

154154
return implementationClass.create(...arguments);
155155
},
@@ -177,8 +177,7 @@ export default {
177177
container directly.
178178
*/
179179
registerImplementation(name, implementation) {
180-
Ember.deprecate('Using the Ember.Location.registerImplementation is no longer supported.' +
181-
' Register your custom location implementation with the container instead.', false);
180+
Ember.deprecate(`Using the Ember.Location.registerImplementation is no longer supported. Register your custom location implementation with the container instead.`, false);
182181

183182
this.implementations[name] = implementation;
184183
},

packages/ember-routing/lib/location/auto_location.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ export default EmberObject.extend({
130130
implementation = 'none';
131131
}
132132

133-
var concrete = this.container.lookup('location:' + implementation);
134-
Ember.assert("Could not find location '" + implementation + "'.", !!concrete);
133+
var concrete = this.container.lookup(`location:${implementation}`);
134+
Ember.assert(`Could not find location '${implementation}'.`, !!concrete);
135135

136136
set(this, 'concreteImplementation', concrete);
137137
},
@@ -239,7 +239,7 @@ export function getHistoryPath(rootURL, location) {
239239
var rootURLIndex = path.indexOf(rootURL);
240240
var routeHash, hashParts;
241241

242-
Ember.assert('Path ' + path + ' does not start with the provided rootURL ' + rootURL, rootURLIndex === 0);
242+
Ember.assert(`Path ${path} does not start with the provided rootURL ${rootURL}`, rootURLIndex === 0);
243243

244244
// By convention, Ember.js routes using HashLocation are required to start
245245
// with `#/`. Anything else should NOT be considered a route and should
@@ -260,7 +260,7 @@ export function getHistoryPath(rootURL, location) {
260260
path = path + routeHash + query;
261261

262262
if (hashParts.length) {
263-
path += '#' + hashParts.join('#');
263+
path += `#${hashParts.join('#')}`;
264264
}
265265
} else {
266266
path = path + query + hash;

packages/ember-routing/lib/location/hash_location.js

+8-9
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export default EmberObject.extend({
6161
// is only included (conventionally) when
6262
// the location.hash has a value
6363
if (originalPath) {
64-
outPath += '#' + originalPath;
64+
outPath += `#${originalPath}`;
6565
}
6666
}
6767

@@ -91,7 +91,7 @@ export default EmberObject.extend({
9191
@param path {String}
9292
*/
9393
replaceURL(path) {
94-
get(this, 'location').replace('#' + path);
94+
get(this, 'location').replace(`#${path}`);
9595
set(this, 'lastSetURL', path);
9696
},
9797

@@ -105,15 +105,14 @@ export default EmberObject.extend({
105105
@param callback {Function}
106106
*/
107107
onUpdateURL(callback) {
108-
var self = this;
109108
var guid = guidFor(this);
110109

111-
Ember.$(window).on('hashchange.ember-location-'+guid, function() {
110+
Ember.$(window).on(`hashchange.ember-location-${guid}`, () => {
112111
run(function() {
113-
var path = self.getURL();
114-
if (get(self, 'lastSetURL') === path) { return; }
112+
var path = this.getURL();
113+
if (get(this, 'lastSetURL') === path) { return; }
115114

116-
set(self, 'lastSetURL', null);
115+
set(this, 'lastSetURL', null);
117116

118117
callback(path);
119118
});
@@ -132,7 +131,7 @@ export default EmberObject.extend({
132131
@param url {String}
133132
*/
134133
formatURL(url) {
135-
return '#' + url;
134+
return `#${url}`;
136135
},
137136

138137
/**
@@ -144,6 +143,6 @@ export default EmberObject.extend({
144143
willDestroy() {
145144
var guid = guidFor(this);
146145

147-
Ember.$(window).off('hashchange.ember-location-'+guid);
146+
Ember.$(window).off(`hashchange.ember-location-${guid}`);
148147
}
149148
});

packages/ember-routing/lib/location/history_location.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -151,15 +151,14 @@ export default EmberObject.extend({
151151
*/
152152
onUpdateURL(callback) {
153153
var guid = guidFor(this);
154-
var self = this;
155154

156-
jQuery(window).on('popstate.ember-location-'+guid, function(e) {
155+
jQuery(window).on(`popstate.ember-location-${guid}`, (e) => {
157156
// Ignore initial page load popstate event in Chrome
158157
if (!popstateFired) {
159158
popstateFired = true;
160-
if (self.getURL() === self._previousURL) { return; }
159+
if (this.getURL() === this._previousURL) { return; }
161160
}
162-
callback(self.getURL());
161+
callback(this.getURL());
163162
});
164163
},
165164

@@ -194,7 +193,7 @@ export default EmberObject.extend({
194193
willDestroy() {
195194
var guid = guidFor(this);
196195

197-
jQuery(window).off('popstate.ember-location-'+guid);
196+
jQuery(window).off(`popstate.ember-location-${guid}`);
198197
},
199198

200199
/**

packages/ember-routing/lib/location/util.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export function getPath(location) {
77
var pathname = location.pathname;
88
// Various versions of IE/Opera don't always return a leading slash
99
if (pathname.charAt(0) !== '/') {
10-
pathname = '/' + pathname;
10+
pathname = `/${pathname}`;
1111
}
1212

1313
return pathname;
@@ -55,7 +55,7 @@ export function getOrigin(location) {
5555
origin = location.protocol + '//' + location.hostname;
5656

5757
if (location.port) {
58-
origin += ':' + location.port;
58+
origin += `:${location.port}`;
5959
}
6060
}
6161

packages/ember-routing/lib/system/controller_for.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212
@private
1313
*/
1414
export default function controllerFor(container, controllerName, lookupOptions) {
15-
return container.lookup('controller:' + controllerName, lookupOptions);
15+
return container.lookup(`controller:${controllerName}`, lookupOptions);
1616
}

packages/ember-routing/lib/system/dsl.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export default DSL;
1515

1616
DSL.prototype = {
1717
route(name, options, callback) {
18+
var dummyErrorRoute = `/_unused_dummy_error_path_route_${name}/:error`;
1819
if (arguments.length === 2 && typeof options === 'function') {
1920
callback = options;
2021
options = {};
@@ -26,7 +27,7 @@ DSL.prototype = {
2627

2728
var type = options.resetNamespace === true ? 'resource' : 'route';
2829
Ember.assert(
29-
"'" + name + "' cannot be used as a " + type + " name.",
30+
`'${name}' cannot be used as a ${type} name.`,
3031
(function() {
3132
if (options.overrideNameAssertion === true) { return true; }
3233

@@ -36,8 +37,8 @@ DSL.prototype = {
3637

3738
if (Ember.FEATURES.isEnabled("ember-routing-named-substates")) {
3839
if (this.enableLoadingSubstates) {
39-
createRoute(this, name + '_loading', { resetNamespace: options.resetNamespace });
40-
createRoute(this, name + '_error', { path: "/_unused_dummy_error_path_route_" + name + "/:error" });
40+
createRoute(this, `${name}_loading`, { resetNamespace: options.resetNamespace });
41+
createRoute(this, `${name}_error`, { path: dummyErrorRoute });
4142
}
4243
}
4344

@@ -48,7 +49,7 @@ DSL.prototype = {
4849
});
4950

5051
createRoute(dsl, 'loading');
51-
createRoute(dsl, 'error', { path: "/_unused_dummy_error_path_route_" + name + "/:error" });
52+
createRoute(dsl, 'error', { path: dummyErrorRoute });
5253

5354
callback.call(dsl);
5455

@@ -101,7 +102,7 @@ function canNest(dsl) {
101102

102103
function getFullName(dsl, name, resetNamespace) {
103104
if (canNest(dsl) && resetNamespace !== true) {
104-
return dsl.parent + "." + name;
105+
return `${dsl.parent}.${name}`;
105106
} else {
106107
return name;
107108
}
@@ -113,7 +114,7 @@ function createRoute(dsl, name, options, callback) {
113114
var fullName = getFullName(dsl, name, options.resetNamespace);
114115

115116
if (typeof options.path !== 'string') {
116-
options.path = "/" + name;
117+
options.path = `/${name}`;
117118
}
118119

119120
dsl.push(options.path, fullName, callback);

0 commit comments

Comments
 (0)