From 7c2242b06f29f0dc780cafb9fcbf1dcf74ec0c5b Mon Sep 17 00:00:00 2001 From: Artem Gurzhii Date: Thu, 12 Jan 2017 18:56:11 +0200 Subject: [PATCH] code refactoring for ember-runtime package --- .../lib/computed/computed_macros.js | 16 +- .../lib/computed/reduce_computed_macros.js | 4 +- packages/ember-runtime/lib/ext/rsvp.js | 2 +- packages/ember-runtime/lib/inject.js | 4 +- packages/ember-runtime/lib/mixins/-proxy.js | 4 +- .../lib/mixins/action_handler.js | 2 +- .../ember-runtime/lib/mixins/enumerable.js | 4 +- .../ember-runtime/lib/mixins/freezable.js | 4 +- .../ember-runtime/lib/mixins/observable.js | 4 +- .../ember-runtime/lib/mixins/promise_proxy.js | 2 +- .../lib/mixins/target_action_support.js | 6 +- .../ember-runtime/lib/system/array_proxy.js | 2 +- .../ember-runtime/lib/system/core_object.js | 288 +++++++++--------- .../ember-runtime/lib/system/each_proxy.js | 2 +- .../ember-runtime/lib/system/lazy_load.js | 2 +- .../ember-runtime/lib/system/namespace.js | 4 +- .../ember-runtime/lib/system/native_array.js | 2 +- packages/ember-runtime/lib/system/string.js | 44 +-- 18 files changed, 185 insertions(+), 211 deletions(-) diff --git a/packages/ember-runtime/lib/computed/computed_macros.js b/packages/ember-runtime/lib/computed/computed_macros.js index 12ba996db75..933b402e132 100644 --- a/packages/ember-runtime/lib/computed/computed_macros.js +++ b/packages/ember-runtime/lib/computed/computed_macros.js @@ -33,7 +33,7 @@ function expandPropertiesToArray(predicateName, properties) { } function generateComputedWithPredicate(name, predicate) { - return function(...properties) { + return (...properties) => { let expandedProperties = expandPropertiesToArray(name, properties); let computedFunc = computed(function() { @@ -49,7 +49,7 @@ function generateComputedWithPredicate(name, predicate) { return get(this, expandedProperties[lastIdx]); }); - return computedFunc.property.apply(computedFunc, expandedProperties); + return computedFunc.property(...expandedProperties); }; } @@ -82,7 +82,7 @@ function generateComputedWithPredicate(name, predicate) { @public */ export function empty(dependentKey) { - return computed(dependentKey + '.length', function() { + return computed(`${dependentKey}.length`, function() { return isEmpty(get(this, dependentKey)); }); } @@ -113,7 +113,7 @@ export function empty(dependentKey) { @public */ export function notEmpty(dependentKey) { - return computed(dependentKey + '.length', function() { + return computed(`${dependentKey}.length`, function() { return !isEmpty(get(this, dependentKey)); }); } @@ -460,9 +460,7 @@ export function lte(dependentKey, value) { a logical `and` on the values of all the original values for properties. @public */ -export let and = generateComputedWithPredicate('and', function(value) { - return value; -}); +export let and = generateComputedWithPredicate('and', value => value); /** A computed property which performs a logical `or` on the @@ -499,9 +497,7 @@ export let and = generateComputedWithPredicate('and', function(value) { a logical `or` on the values of all the original values for properties. @public */ -export let or = generateComputedWithPredicate('or', function(value) { - return !value; -}); +export let or = generateComputedWithPredicate('or', value => !value); /** Creates a new property that is an alias for another property diff --git a/packages/ember-runtime/lib/computed/reduce_computed_macros.js b/packages/ember-runtime/lib/computed/reduce_computed_macros.js index b5df4dd3ea2..a0220c6fe01 100644 --- a/packages/ember-runtime/lib/computed/reduce_computed_macros.js +++ b/packages/ember-runtime/lib/computed/reduce_computed_macros.js @@ -688,7 +688,7 @@ function propertySort(itemsKey, sortPropertiesKey) { let activeObservers = activeObserversMap.get(this); if (activeObservers) { - activeObservers.forEach(args => removeObserver.apply(null, args)); + activeObservers.forEach(args => removeObserver(...args)); } function sortPropertyDidChange() { @@ -698,7 +698,7 @@ function propertySort(itemsKey, sortPropertiesKey) { activeObservers = normalizedSortProperties.map(([prop]) => { let path = itemsKeyIsAtThis ? `@each.${prop}` : `${itemsKey}.@each.${prop}`; let args = [this, path, sortPropertyDidChange]; - addObserver.apply(null, args); + addObserver(...args); return args; }); diff --git a/packages/ember-runtime/lib/ext/rsvp.js b/packages/ember-runtime/lib/ext/rsvp.js index eb392f3e45f..9e238ab0f0f 100644 --- a/packages/ember-runtime/lib/ext/rsvp.js +++ b/packages/ember-runtime/lib/ext/rsvp.js @@ -33,7 +33,7 @@ function errorFor(reason) { } if (reason.name === 'UnrecognizedURLError') { - assert('The URL \'' + reason.message + '\' did not match any routes in your application', false); + assert(`The URL '${reason.message}' did not match any routes in your application`, false); return; } diff --git a/packages/ember-runtime/lib/inject.js b/packages/ember-runtime/lib/inject.js index 6207574cc26..8f8ebeeb6ea 100644 --- a/packages/ember-runtime/lib/inject.js +++ b/packages/ember-runtime/lib/inject.js @@ -33,9 +33,7 @@ const typeValidators = {}; export function createInjectionHelper(type, validator) { typeValidators[type] = validator; - inject[type] = function(name) { - return new InjectedProperty(type, name); - }; + inject[type] = name => new InjectedProperty(type, name); } /** diff --git a/packages/ember-runtime/lib/mixins/-proxy.js b/packages/ember-runtime/lib/mixins/-proxy.js index b1d466c74a9..712bcde1521 100644 --- a/packages/ember-runtime/lib/mixins/-proxy.js +++ b/packages/ember-runtime/lib/mixins/-proxy.js @@ -99,13 +99,13 @@ export default Mixin.create({ _debugContainerKey: null, willWatchProperty(key) { - let contentKey = 'content.' + key; + let contentKey = `content.${key}`; _addBeforeObserver(this, contentKey, null, contentPropertyWillChange); addObserver(this, contentKey, null, contentPropertyDidChange); }, didUnwatchProperty(key) { - let contentKey = 'content.' + key; + let contentKey = `content.${key}`; _removeBeforeObserver(this, contentKey, null, contentPropertyWillChange); removeObserver(this, contentKey, null, contentPropertyDidChange); }, diff --git a/packages/ember-runtime/lib/mixins/action_handler.js b/packages/ember-runtime/lib/mixins/action_handler.js index 18025b7bd83..47432d38ce9 100644 --- a/packages/ember-runtime/lib/mixins/action_handler.js +++ b/packages/ember-runtime/lib/mixins/action_handler.js @@ -184,7 +184,7 @@ const ActionHandler = Mixin.create({ let target = get(this, 'target'); if (target) { assert( - 'The `target` for ' + this + ' (' + target + ') does not have a `send` method', + `The \`target\` for ${this} (${target}) does not have a \`send\` method`, typeof target.send === 'function' ); target.send(...arguments); diff --git a/packages/ember-runtime/lib/mixins/enumerable.js b/packages/ember-runtime/lib/mixins/enumerable.js index 1ff4e98a5d1..c3e344b23b1 100644 --- a/packages/ember-runtime/lib/mixins/enumerable.js +++ b/packages/ember-runtime/lib/mixins/enumerable.js @@ -396,7 +396,7 @@ const Enumerable = Mixin.create({ filter(callback, target) { let ret = emberA(); - this.forEach(function(x, idx, i) { + this.forEach((x, idx, i) => { if (callback.call(target, x, idx, i)) { ret.push(x); } @@ -738,7 +738,7 @@ const Enumerable = Mixin.create({ invoke(methodName, ...args) { let ret = emberA(); - this.forEach(function(x, idx) { + this.forEach((x, idx) => { let method = x && x[methodName]; if ('function' === typeof method) { diff --git a/packages/ember-runtime/lib/mixins/freezable.js b/packages/ember-runtime/lib/mixins/freezable.js index 8a3451a250d..a86b6f2724d 100644 --- a/packages/ember-runtime/lib/mixins/freezable.js +++ b/packages/ember-runtime/lib/mixins/freezable.js @@ -68,7 +68,7 @@ import { @deprecated Use `Object.freeze` instead. @private */ -export var Freezable = Mixin.create({ +export const Freezable = Mixin.create({ init() { deprecate( @@ -108,4 +108,4 @@ export var Freezable = Mixin.create({ }); -export var FROZEN_ERROR = 'Frozen object cannot be modified.'; +export const FROZEN_ERROR = 'Frozen object cannot be modified.'; diff --git a/packages/ember-runtime/lib/mixins/observable.js b/packages/ember-runtime/lib/mixins/observable.js index 327cb56a274..ab6d270c7d9 100644 --- a/packages/ember-runtime/lib/mixins/observable.js +++ b/packages/ember-runtime/lib/mixins/observable.js @@ -158,7 +158,7 @@ export default Mixin.create({ @public */ getProperties(...args) { - return getProperties.apply(null, [this].concat(args)); + return getProperties(...[this].concat(args)); }, /** @@ -409,7 +409,7 @@ export default Mixin.create({ @private */ hasObserverFor(key) { - return hasListeners(this, key + ':change'); + return hasListeners(this, `${key}:change`); }, /** diff --git a/packages/ember-runtime/lib/mixins/promise_proxy.js b/packages/ember-runtime/lib/mixins/promise_proxy.js index dc31dada53d..ef872d89e51 100644 --- a/packages/ember-runtime/lib/mixins/promise_proxy.js +++ b/packages/ember-runtime/lib/mixins/promise_proxy.js @@ -29,7 +29,7 @@ function tap(proxy, promise) { }, reason => { if (!proxy.isDestroyed && !proxy.isDestroying) { setProperties(proxy, { - reason: reason, + reason, isRejected: true }); } diff --git a/packages/ember-runtime/lib/mixins/target_action_support.js b/packages/ember-runtime/lib/mixins/target_action_support.js index 373f0fc1c1e..b46d69ae71a 100644 --- a/packages/ember-runtime/lib/mixins/target_action_support.js +++ b/packages/ember-runtime/lib/mixins/target_action_support.js @@ -118,10 +118,10 @@ export default Mixin.create({ let ret; if (target.send) { - ret = target.send.apply(target, args(actionContext, action)); + ret = target.send(...args(actionContext, action)); } else { - assert('The action \'' + action + '\' did not exist on ' + target, typeof target[action] === 'function'); - ret = target[action].apply(target, args(actionContext)); + assert(`The action '${action}' did not exist on ${target}`, typeof target[action] === 'function'); + ret = target[action](...args(actionContext)); } if (ret !== false) { diff --git a/packages/ember-runtime/lib/system/array_proxy.js b/packages/ember-runtime/lib/system/array_proxy.js index 16a797b1222..9381bb8962a 100644 --- a/packages/ember-runtime/lib/system/array_proxy.js +++ b/packages/ember-runtime/lib/system/array_proxy.js @@ -265,7 +265,7 @@ export default EmberObject.extend(MutableArray, { _replace(idx, amt, objects) { let content = get(this, 'content'); - assert('The content property of ' + this.constructor + ' should be set before modifying it', content); + assert(`The content property of ${this.constructor} should be set before modifying it`, content); if (content) { this.replaceContent(idx, amt, objects); } diff --git a/packages/ember-runtime/lib/system/core_object.js b/packages/ember-runtime/lib/system/core_object.js index a13268e5180..6df0b872fca 100644 --- a/packages/ember-runtime/lib/system/core_object.js +++ b/packages/ember-runtime/lib/system/core_object.js @@ -43,11 +43,11 @@ import { import ActionHandler from '../mixins/action_handler'; import { validatePropertyInjections } from '../inject'; -var schedule = run.schedule; -var applyMixin = Mixin._apply; -var finishPartial = Mixin.finishPartial; -var reopen = Mixin.prototype.reopen; -var hasCachedComputedProperties = false; +let schedule = run.schedule; +let applyMixin = Mixin._apply; +let finishPartial = Mixin.finishPartial; +let reopen = Mixin.prototype.reopen; +let hasCachedComputedProperties = false; export const POST_INIT = symbol('POST_INIT'); @@ -56,148 +56,150 @@ function makeCtor() { // method a lot faster. This is glue code so we want it to be as fast as // possible. - var wasApplied = false; - var initProperties; + let wasApplied = false; + let initProperties; - var Class = function() { - if (!wasApplied) { - Class.proto(); // prepare prototype... - } - - if (arguments.length > 0) { - initProperties = [arguments[0]]; - } + class Class { + constructor() { + if (!wasApplied) { + Class.proto(); // prepare prototype... + } - this.__defineNonEnumerable(GUID_KEY_PROPERTY); - var m = meta(this); - var proto = m.proto; - m.proto = this; - if (initProperties) { - // capture locally so we can clear the closed over variable - var props = initProperties; - initProperties = null; - - var concatenatedProperties = this.concatenatedProperties; - var mergedProperties = this.mergedProperties; - - for (var i = 0; i < props.length; i++) { - var properties = props[i]; - - assert( - 'Ember.Object.create no longer supports mixing in other ' + - 'definitions, use .extend & .create separately instead.', - !(properties instanceof Mixin) - ); - - if (typeof properties !== 'object' && properties !== undefined) { - throw new EmberError('Ember.Object.create only accepts objects.'); - } + if (arguments.length > 0) { + initProperties = [arguments[0]]; + } - if (!properties) { continue; } + this.__defineNonEnumerable(GUID_KEY_PROPERTY); + let m = meta(this); + let proto = m.proto; + m.proto = this; + if (initProperties) { + // capture locally so we can clear the closed over variable + let props = initProperties; + initProperties = null; - var keyNames = Object.keys(properties); + let concatenatedProperties = this.concatenatedProperties; + let mergedProperties = this.mergedProperties; - for (var j = 0; j < keyNames.length; j++) { - var keyName = keyNames[j]; - var value = properties[keyName]; + for (let i = 0; i < props.length; i++) { + let properties = props[i]; + assert( + 'Ember.Object.create no longer supports mixing in other ' + + 'definitions, use .extend & .create separately instead.', + !(properties instanceof Mixin) + ); - if (detectBinding(keyName)) { - m.writeBindings(keyName, value); + if (typeof properties !== 'object' && properties !== undefined) { + throw new EmberError('Ember.Object.create only accepts objects.'); } - var possibleDesc = this[keyName]; - var desc = (possibleDesc !== null && typeof possibleDesc === 'object' && possibleDesc.isDescriptor) ? possibleDesc : undefined; + if (!properties) { continue; } - assert( - 'Ember.Object.create no longer supports defining computed ' + - 'properties. Define computed properties using extend() or reopen() ' + - 'before calling create().', - !(value instanceof ComputedProperty) - ); - assert( - 'Ember.Object.create no longer supports defining methods that call _super.', - !(typeof value === 'function' && value.toString().indexOf('._super') !== -1) - ); - assert( - '`actions` must be provided at extend time, not at create time, ' + - 'when Ember.ActionHandler is used (i.e. views, controllers & routes).', - !((keyName === 'actions') && ActionHandler.detect(this)) - ); + let keyNames = Object.keys(properties); - if (concatenatedProperties && - concatenatedProperties.length > 0 && - concatenatedProperties.indexOf(keyName) >= 0) { - var baseValue = this[keyName]; + for (let j = 0; j < keyNames.length; j++) { + let keyName = keyNames[j]; + let value = properties[keyName]; - if (baseValue) { - if ('function' === typeof baseValue.concat) { - value = baseValue.concat(value); + if (detectBinding(keyName)) { + m.writeBindings(keyName, value); + } + + let possibleDesc = this[keyName]; + let desc = (possibleDesc !== null && typeof possibleDesc === 'object' && possibleDesc.isDescriptor) ? possibleDesc : undefined; + + assert( + 'Ember.Object.create no longer supports defining computed ' + + 'properties. Define computed properties using extend() or reopen() ' + + 'before calling create().', + !(value instanceof ComputedProperty) + ); + assert( + 'Ember.Object.create no longer supports defining methods that call _super.', + !(typeof value === 'function' && value.toString().indexOf('._super') !== -1) + ); + assert( + '`actions` must be provided at extend time, not at create time, ' + + 'when Ember.ActionHandler is used (i.e. views, controllers & routes).', + !((keyName === 'actions') && ActionHandler.detect(this)) + ); + + if (concatenatedProperties && + concatenatedProperties.length > 0 && + concatenatedProperties.indexOf(keyName) >= 0) { + let baseValue = this[keyName]; + + if (baseValue) { + if ('function' === typeof baseValue.concat) { + value = baseValue.concat(value); + } else { + value = makeArray(baseValue).concat(value); + } } else { - value = makeArray(baseValue).concat(value); + value = makeArray(value); } - } else { - value = makeArray(value); } - } - if (mergedProperties && - mergedProperties.length && - mergedProperties.indexOf(keyName) >= 0) { - var originalValue = this[keyName]; + if (mergedProperties && + mergedProperties.length && + mergedProperties.indexOf(keyName) >= 0) { + let originalValue = this[keyName]; - value = assign({}, originalValue, value); - } + value = assign({}, originalValue, value); + } - if (desc) { - desc.set(this, keyName, value); - } else { - if (typeof this.setUnknownProperty === 'function' && !(keyName in this)) { - this.setUnknownProperty(keyName, value); + if (desc) { + desc.set(this, keyName, value); } else { - if (isFeatureEnabled('mandatory-setter')) { - defineProperty(this, keyName, null, value); // setup mandatory setter + if (typeof this.setUnknownProperty === 'function' && !(keyName in this)) { + this.setUnknownProperty(keyName, value); } else { - this[keyName] = value; + if (isFeatureEnabled('mandatory-setter')) { + defineProperty(this, keyName, null, value); // setup mandatory setter + } else { + this[keyName] = value; + } } } } } } - } - finishPartial(this, m); + finishPartial(this, m); - this.init.apply(this, arguments); + this.init(...arguments); - this[POST_INIT](); + this[POST_INIT](); - m.proto = proto; - finishChains(this); - sendEvent(this, 'init'); - }; + m.proto = proto; + finishChains(this); + sendEvent(this, 'init'); + } - Class.toString = Mixin.prototype.toString; - Class.willReopen = function() { - if (wasApplied) { - Class.PrototypeMixin = Mixin.create(Class.PrototypeMixin); + static willReopen() { + if (wasApplied) { + Class.PrototypeMixin = Mixin.create(Class.PrototypeMixin); + } + + wasApplied = false; } - wasApplied = false; - }; + static _initProperties(args) { initProperties = args; } - Class._initProperties = function(args) { initProperties = args; }; + static proto() { + let superclass = Class.superclass; + if (superclass) { superclass.proto(); } - Class.proto = function() { - var superclass = Class.superclass; - if (superclass) { superclass.proto(); } + if (!wasApplied) { + wasApplied = true; + Class.PrototypeMixin.applyPartial(Class.prototype); + } - if (!wasApplied) { - wasApplied = true; - Class.PrototypeMixin.applyPartial(Class.prototype); + return this.prototype; } + } - return this.prototype; - }; + Class.toString = Mixin.prototype.toString; return Class; } @@ -207,8 +209,8 @@ function makeCtor() { @namespace Ember @public */ -var CoreObject = makeCtor(); -CoreObject.toString = function() { return 'Ember.CoreObject'; }; +let CoreObject = makeCtor(); +CoreObject.toString = () => 'Ember.CoreObject'; CoreObject.PrototypeMixin = Mixin.create({ reopen(...args) { applyMixin(this, args, true); @@ -541,9 +543,9 @@ CoreObject.PrototypeMixin = Mixin.create({ @public */ toString() { - var hasToStringExtension = typeof this.toStringExtension === 'function'; - var extension = hasToStringExtension ? ':' + this.toStringExtension() : ''; - var ret = '<' + (this[NAME_KEY] || this.constructor.toString()) + ':' + guidFor(this) + extension + '>'; + let hasToStringExtension = typeof this.toStringExtension === 'function'; + let extension = hasToStringExtension ? `:${this.toStringExtension()}` : ''; + let ret = `<${this[NAME_KEY] || this.constructor.toString()}:${guidFor(this)}${extension}>`; return ret; } @@ -553,7 +555,7 @@ CoreObject.PrototypeMixin.ownerConstructor = CoreObject; CoreObject.__super__ = null; -var ClassMixinProps = { +let ClassMixinProps = { ClassMixin: REQUIRED, @@ -593,7 +595,7 @@ var ClassMixinProps = { ```javascript const Person = Ember.Object.extend({ say(thing) { - var name = this.get('name'); + let name = this.get('name'); alert(`${name} says: ${thing}`); } }); @@ -650,8 +652,8 @@ var ClassMixinProps = { @public */ extend() { - var Class = makeCtor(); - var proto; + let Class = makeCtor(); + let proto; Class.ClassMixin = Mixin.create(this.ClassMixin); Class.PrototypeMixin = Mixin.create(this.PrototypeMixin); @@ -711,7 +713,7 @@ var ClassMixinProps = { @public */ create(...args) { - var C = this; + let C = this; if (args.length > 0) { this._initProperties(args); } @@ -839,7 +841,7 @@ var ClassMixinProps = { ```javascript person: Ember.computed(function() { - var personId = this.get('personId'); + let personId = this.get('personId'); return Person.create({ id: personId }); }).meta({ type: Person }) ``` @@ -859,13 +861,12 @@ var ClassMixinProps = { @private */ metaForProperty(key) { - var proto = this.proto(); - var possibleDesc = proto[key]; - var desc = (possibleDesc !== null && typeof possibleDesc === 'object' && possibleDesc.isDescriptor) ? possibleDesc : undefined; + let proto = this.proto(); + let possibleDesc = proto[key]; + let desc = (possibleDesc !== null && typeof possibleDesc === 'object' && possibleDesc.isDescriptor) ? possibleDesc : undefined; assert( - 'metaForProperty() could not find a computed property ' + - 'with key \'' + key + '\'.', + `metaForProperty() could not find a computed property with key '${key}'.`, !!desc && desc instanceof ComputedProperty ); return desc._meta || {}; @@ -873,16 +874,16 @@ var ClassMixinProps = { _computedProperties: computed(function() { hasCachedComputedProperties = true; - var proto = this.proto(); - var property; - var properties = []; + let proto = this.proto(); + let property; + let properties = []; - for (var name in proto) { + for (let name in proto) { property = proto[name]; if (property && property.isDescriptor) { properties.push({ - name: name, + name, meta: property._meta }); } @@ -901,12 +902,12 @@ var ClassMixinProps = { @private */ eachComputedProperty(callback, binding) { - var property; - var empty = {}; + let property; + let empty = {}; - var properties = get(this, '_computedProperties'); + let properties = get(this, '_computedProperties'); - for (var i = 0; i < properties.length; i++) { + for (let i = 0; i < properties.length; i++) { property = properties[i]; callback.call(binding || this, property.name, property.meta || empty); } @@ -917,7 +918,7 @@ function injectedPropertyAssertion() { assert('Injected properties are invalid', validatePropertyInjections(this)); } -runInDebug(function() { +runInDebug(() => { /** Provides lookup-time type validation for injected properties. @@ -936,21 +937,22 @@ runInDebug(function() { @private */ ClassMixinProps._lazyInjections = function() { - var injections = {}; - var proto = this.proto(); - var key, desc; + let injections = {}; + let proto = this.proto(); + let key; + let desc; for (key in proto) { desc = proto[key]; if (desc instanceof InjectedProperty) { - injections[key] = desc.type + ':' + (desc.name || key); + injections[key] = `${desc.type}:${desc.name || key}`; } } return injections; }; -var ClassMixin = Mixin.create(ClassMixinProps); +let ClassMixin = Mixin.create(ClassMixinProps); ClassMixin.ownerConstructor = CoreObject; @@ -962,7 +964,7 @@ CoreObject.reopen({ didDefineProperty(proto, key, value) { if (hasCachedComputedProperties === false) { return; } if (value instanceof ComputedProperty) { - var cache = meta(this.constructor).readableCache(); + let cache = meta(this.constructor).readableCache(); if (cache && cache._computedProperties !== undefined) { cache._computedProperties = undefined; diff --git a/packages/ember-runtime/lib/system/each_proxy.js b/packages/ember-runtime/lib/system/each_proxy.js index c239cee721d..590d903dc52 100644 --- a/packages/ember-runtime/lib/system/each_proxy.js +++ b/packages/ember-runtime/lib/system/each_proxy.js @@ -111,7 +111,7 @@ function addObserverForContentKey(content, keyName, proxy, idx, loc) { while (--loc >= idx) { let item = objectAt(content, loc); if (item) { - assert('When using @each to observe the array ' + content + ', the array must return an object', typeof item === 'object'); + assert(`When using @each to observe the array ${content}, the array must return an object`, typeof item === 'object'); _addBeforeObserver(item, keyName, proxy, 'contentKeyWillChange'); addObserver(item, keyName, proxy, 'contentKeyDidChange'); } diff --git a/packages/ember-runtime/lib/system/lazy_load.js b/packages/ember-runtime/lib/system/lazy_load.js index 604a7286e96..06075de72ea 100644 --- a/packages/ember-runtime/lib/system/lazy_load.js +++ b/packages/ember-runtime/lib/system/lazy_load.js @@ -56,7 +56,7 @@ export function runLoadHooks(name, object) { let window = environment.window; if (window && typeof CustomEvent === 'function') { - let event = new CustomEvent(name, { detail: object, name: name }); + let event = new CustomEvent(name, { detail: object, name }); window.dispatchEvent(event); } diff --git a/packages/ember-runtime/lib/system/namespace.js b/packages/ember-runtime/lib/system/namespace.js index 23534db7a5e..75b4cba60f4 100644 --- a/packages/ember-runtime/lib/system/namespace.js +++ b/packages/ember-runtime/lib/system/namespace.js @@ -77,7 +77,7 @@ const Namespace = EmberObject.extend({ Namespace.reopenClass({ NAMESPACES: [Ember], NAMESPACES_BY_ID: { - Ember: Ember + Ember }, PROCESSED: false, processAll: processAllNamespaces, @@ -185,7 +185,7 @@ function calculateToString(target) { return str; } else { str = superClassString(target); - str = str ? '(subclass of ' + str + ')' : str; + str = str ? `(subclass of ${str})` : str; } } if (str) { diff --git a/packages/ember-runtime/lib/system/native_array.js b/packages/ember-runtime/lib/system/native_array.js index 5ba5fbf6bda..60e4ce8004a 100644 --- a/packages/ember-runtime/lib/system/native_array.js +++ b/packages/ember-runtime/lib/system/native_array.js @@ -104,7 +104,7 @@ NativeArray.keys().forEach((methodName) => { } }); -NativeArray = NativeArray.without.apply(NativeArray, ignore); +NativeArray = NativeArray.without(...ignore); /** Creates an `Ember.NativeArray` from an Array like object. diff --git a/packages/ember-runtime/lib/system/string.js b/packages/ember-runtime/lib/system/string.js index 307350e05bc..e97e29b718c 100644 --- a/packages/ember-runtime/lib/system/string.js +++ b/packages/ember-runtime/lib/system/string.js @@ -14,32 +14,20 @@ import { const STRING_DASHERIZE_REGEXP = (/[ _]/g); -const STRING_DASHERIZE_CACHE = new Cache(1000, function(key) { - return decamelize(key).replace(STRING_DASHERIZE_REGEXP, '-'); -}); +const STRING_DASHERIZE_CACHE = new Cache(1000, key => decamelize(key).replace(STRING_DASHERIZE_REGEXP, '-')); const STRING_CAMELIZE_REGEXP_1 = (/(\-|\_|\.|\s)+(.)?/g); const STRING_CAMELIZE_REGEXP_2 = (/(^|\/)([A-Z])/g); -const CAMELIZE_CACHE = new Cache(1000, function(key) { - return key.replace(STRING_CAMELIZE_REGEXP_1, function(match, separator, chr) { - return chr ? chr.toUpperCase() : ''; - }).replace(STRING_CAMELIZE_REGEXP_2, function(match, separator, chr) { - return match.toLowerCase(); - }); -}); +const CAMELIZE_CACHE = new Cache(1000, key => key.replace(STRING_CAMELIZE_REGEXP_1, (match, separator, chr) => chr ? chr.toUpperCase() : '').replace(STRING_CAMELIZE_REGEXP_2, (match, separator, chr) => match.toLowerCase())); const STRING_CLASSIFY_REGEXP_1 = (/^(\-|_)+(.)?/); const STRING_CLASSIFY_REGEXP_2 = (/(.)(\-|\_|\.|\s)+(.)?/g); const STRING_CLASSIFY_REGEXP_3 = (/(^|\/|\.)([a-z])/g); -const CLASSIFY_CACHE = new Cache(1000, function(str) { - let replace1 = function(match, separator, chr) { - return chr ? ('_' + chr.toUpperCase()) : ''; - }; - let replace2 = function(match, initialChar, separator, chr) { - return initialChar + (chr ? chr.toUpperCase() : ''); - }; +const CLASSIFY_CACHE = new Cache(1000, str => { + let replace1 = (match, separator, chr) => chr ? (`_${chr.toUpperCase()}`) : ''; + let replace2 = (match, initialChar, separator, chr) => initialChar + (chr ? chr.toUpperCase() : ''); let parts = str.split('/'); for (let i = 0; i < parts.length; i++) { parts[i] = parts[i] @@ -47,32 +35,22 @@ const CLASSIFY_CACHE = new Cache(1000, function(str) { .replace(STRING_CLASSIFY_REGEXP_2, replace2); } return parts.join('/') - .replace(STRING_CLASSIFY_REGEXP_3, function(match, separator, chr) { - return match.toUpperCase(); - }); + .replace(STRING_CLASSIFY_REGEXP_3, (match, separator, chr) => match.toUpperCase()); }); const STRING_UNDERSCORE_REGEXP_1 = (/([a-z\d])([A-Z]+)/g); const STRING_UNDERSCORE_REGEXP_2 = (/\-|\s+/g); -const UNDERSCORE_CACHE = new Cache(1000, function(str) { - return str.replace(STRING_UNDERSCORE_REGEXP_1, '$1_$2'). - replace(STRING_UNDERSCORE_REGEXP_2, '_').toLowerCase(); -}); +const UNDERSCORE_CACHE = new Cache(1000, str => str.replace(STRING_UNDERSCORE_REGEXP_1, '$1_$2'). + replace(STRING_UNDERSCORE_REGEXP_2, '_').toLowerCase()); const STRING_CAPITALIZE_REGEXP = (/(^|\/)([a-z])/g); -const CAPITALIZE_CACHE = new Cache(1000, function(str) { - return str.replace(STRING_CAPITALIZE_REGEXP, function(match, separator, chr) { - return match.toUpperCase(); - }); -}); +const CAPITALIZE_CACHE = new Cache(1000, str => str.replace(STRING_CAPITALIZE_REGEXP, (match, separator, chr) => match.toUpperCase())); const STRING_DECAMELIZE_REGEXP = (/([a-z\d])([A-Z])/g); -const DECAMELIZE_CACHE = new Cache(1000, function(str) { - return str.replace(STRING_DECAMELIZE_REGEXP, '$1_$2').toLowerCase(); -}); +const DECAMELIZE_CACHE = new Cache(1000, str => str.replace(STRING_DECAMELIZE_REGEXP, '$1_$2').toLowerCase()); function _fmt(str, formats) { let cachedFormats = formats; @@ -87,7 +65,7 @@ function _fmt(str, formats) { // first, replace any ORDERED replacements. let idx = 0; // the current index for non-numerical replacements - return str.replace(/%@([0-9]+)?/g, function(s, argIndex) { + return str.replace(/%@([0-9]+)?/g, (s, argIndex) => { argIndex = (argIndex) ? parseInt(argIndex, 10) - 1 : idx++; s = cachedFormats[argIndex]; return (s === null) ? '(null)' : (s === undefined) ? '' : inspect(s);