Skip to content

Commit

Permalink
Merge pull request #14830 from artemgurzhii/ember-runtime
Browse files Browse the repository at this point in the history
Code refactoring for ember-runtime package
  • Loading branch information
stefanpenner authored Jan 17, 2017
2 parents 02ac575 + 7c2242b commit d3314cd
Show file tree
Hide file tree
Showing 18 changed files with 185 additions and 211 deletions.
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 @@ -404,7 +404,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

0 comments on commit d3314cd

Please sign in to comment.