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-runtime package #14830

Merged
merged 1 commit 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
16 changes: 6 additions & 10 deletions packages/ember-runtime/lib/computed/computed_macros.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -49,7 +49,7 @@ function generateComputedWithPredicate(name, predicate) {
return get(this, expandedProperties[lastIdx]);
});

return computedFunc.property.apply(computedFunc, expandedProperties);
return computedFunc.property(...expandedProperties);
};
}

Expand Down Expand Up @@ -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));
});
}
Expand Down Expand Up @@ -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));
});
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions packages/ember-runtime/lib/computed/reduce_computed_macros.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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;
});

Expand Down
2 changes: 1 addition & 1 deletion packages/ember-runtime/lib/ext/rsvp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 1 addition & 3 deletions packages/ember-runtime/lib/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/ember-runtime/lib/mixins/-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
Expand Down
2 changes: 1 addition & 1 deletion packages/ember-runtime/lib/mixins/action_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions packages/ember-runtime/lib/mixins/enumerable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions packages/ember-runtime/lib/mixins/freezable.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ import {
@deprecated Use `Object.freeze` instead.
@private
*/
export var Freezable = Mixin.create({
export const Freezable = Mixin.create({

init() {
deprecate(
Expand Down Expand Up @@ -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.';
4 changes: 2 additions & 2 deletions packages/ember-runtime/lib/mixins/observable.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export default Mixin.create({
@public
*/
getProperties(...args) {
return getProperties.apply(null, [this].concat(args));
return getProperties(...[this].concat(args));
},

/**
Expand Down Expand Up @@ -409,7 +409,7 @@ export default Mixin.create({
@private
*/
hasObserverFor(key) {
return hasListeners(this, key + ':change');
return hasListeners(this, `${key}:change`);
},

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/ember-runtime/lib/mixins/promise_proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function tap(proxy, promise) {
}, reason => {
if (!proxy.isDestroyed && !proxy.isDestroying) {
setProperties(proxy, {
reason: reason,
reason,
isRejected: true
});
}
Expand Down
6 changes: 3 additions & 3 deletions packages/ember-runtime/lib/mixins/target_action_support.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion packages/ember-runtime/lib/system/array_proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Loading