Skip to content

Commit

Permalink
Use default parameters
Browse files Browse the repository at this point in the history
Move to default parameters where appropriate
  • Loading branch information
thoov committed Jan 19, 2016
1 parent 551a231 commit 586d4c6
Show file tree
Hide file tree
Showing 18 changed files with 31 additions and 48 deletions.
9 changes: 2 additions & 7 deletions packages/container/lib/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,7 @@ function isSingleton(container, fullName) {
return container.registry.getOption(fullName, 'singleton') !== false;
}

function lookup(container, _fullName, _options) {
let options = _options || {};
let fullName = _fullName;

function lookup(container, fullName, options = {}) {
if (isEnabled('ember-htmlbars-local-lookup')) {
if (options.source) {
fullName = container.registry.expandLocalLookup(fullName, options);
Expand Down Expand Up @@ -249,10 +246,8 @@ function buildInjections(/* container, ...injections */) {
return hash;
}

function factoryFor(container, _fullName, _options) {
let options = _options || {};
function factoryFor(container, fullName, options = {}) {
let registry = container.registry;
let fullName = _fullName;

if (isEnabled('ember-htmlbars-local-lookup')) {
if (options.source) {
Expand Down
7 changes: 3 additions & 4 deletions packages/container/lib/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ Registry.prototype = {
@param {Function} factory
@param {Object} options
*/
register(fullName, factory, options) {
register(fullName, factory, options = {}) {
assert('fullName must be a proper full name', this.validateFullName(fullName));

if (factory === undefined) {
Expand All @@ -183,7 +183,7 @@ Registry.prototype = {

delete this._failCache[normalizedName];
this.registrations[normalizedName] = factory;
this._options[normalizedName] = (options || {});
this._options[normalizedName] = options;
},

/**
Expand Down Expand Up @@ -402,8 +402,7 @@ Registry.prototype = {
@param {String} fullName
@param {Object} options
*/
options(fullName, _options) {
let options = _options || {};
options(fullName, options = {}) {
var normalizedName = this.normalize(fullName);
this._options[normalizedName] = options;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,14 @@ export default ComponentNodeManager;
ComponentNodeManager.create = function ComponentNodeManager_create(renderNode, env, options) {
let { tagName,
params,
attrs,
attrs = {},
parentView,
parentScope,
isAngleBracket,
component,
layout,
templates } = options;

attrs = attrs || {};

component = component || (isAngleBracket ? GlimmerComponent : LegacyEmberComponent);

let createOptions = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ if (isEnabled('ember-htmlbars-component-generation')) {
}

function renderComponent(tag, component) {
let { params, hash, yielded, implementation } = component;
params = params || [];
hash = hash || {};
let { params = [], hash = {}, yielded, implementation } = component;
let stringParams = params.join(' ');
let stringHash = Object.keys(hash)
.map(key => `${key}=${hash[key]}`)
Expand Down
4 changes: 2 additions & 2 deletions packages/ember-htmlbars/tests/helpers/loc_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import EmberView from 'ember-views/views/view';
import compile from 'ember-template-compiler/system/compile';
import { runAppend, runDestroy } from 'ember-runtime/tests/utils';

function buildView(template, context) {
function buildView(template, context = {}) {
return EmberView.create({
template: compile(template),
context: (context || {})
context
});
}

Expand Down
4 changes: 1 addition & 3 deletions packages/ember-routing/tests/system/router_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ import { setOwner } from 'container/owner';

var owner;

function createRouter(settings, options) {
options = options || {};

function createRouter(settings, options = {}) {
var CustomRouter = Router.extend();
var router = CustomRouter.create(settings);

Expand Down
3 changes: 1 addition & 2 deletions packages/ember-runtime/lib/mixins/target_action_support.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ var TargetActionSupport = Mixin.create({
@return {Boolean} true if the action was sent successfully and did not return false
@private
*/
triggerAction(opts) {
opts = opts || {};
triggerAction(opts = {}) {
var action = opts.action || get(this, 'action');
var target = opts.target || get(this, 'targetObject');
var actionContext = opts.actionContext;
Expand Down
5 changes: 2 additions & 3 deletions packages/ember-runtime/lib/system/native_array.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,9 @@ var A;

if (Ember.EXTEND_PROTOTYPES === true || Ember.EXTEND_PROTOTYPES.Array) {
NativeArray.apply(Array.prototype);
A = function (arr) { return arr || []; };
A = function (arr = []) { return arr; };
} else {
A = function (arr) {
if (arr === undefined) { arr = []; }
A = function (arr = []) {
return EmberArray.detect(arr) ? arr : NativeArray.apply(arr);
};
}
Expand Down
4 changes: 2 additions & 2 deletions packages/ember-runtime/tests/mixins/array_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ var TestArray = EmberObject.extend(EmberArray, {

_content: null,

init(ary) {
this._content = ary || [];
init(ary = []) {
this._content = ary;
},

// some methods to modify the array so we can test changes. Note that
Expand Down
5 changes: 2 additions & 3 deletions packages/ember-runtime/tests/mixins/enumerable_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ var TestEnumerable = EmberObject.extend(Enumerable, {

_content: null,

init(ary) {
this._content = ary || [];
init(ary = []) {
this._content = ary;
},

addObject(obj) {
Expand Down Expand Up @@ -347,4 +347,3 @@ QUnit.test('removing enumerable observer should disable', function() {
obj.enumerableContentDidChange();
deepEqual(observer._after, null);
});

4 changes: 2 additions & 2 deletions packages/ember-runtime/tests/mixins/mutable_array_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ var TestMutableArray = EmberObject.extend(MutableArray, {

_content: null,

init(ary) {
this._content = emberA(ary || []);
init(ary = []) {
this._content = emberA(ary);
},

replace(idx, amt, objects) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import Ember from 'ember-metal/core';
import { assert } from 'ember-metal/debug';
import calculateLocationDisplay from 'ember-template-compiler/system/calculate-location-display';

function AssertNoViewAndControllerPaths(options) {
function AssertNoViewAndControllerPaths(options = {}) {
// set later within HTMLBars to the syntax package
this.syntax = null;
this.options = options || {};
this.options = options;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import Ember from 'ember-metal/core';
import { assert } from 'ember-metal/debug';
import calculateLocationDisplay from 'ember-template-compiler/system/calculate-location-display';

function AssertNoViewHelper(options) {
function AssertNoViewHelper(options = {}) {
// set later within HTMLBars to the syntax package
this.syntax = null;
this.options = options || {};
this.options = options;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
@class TransformEachInToHash
@private
*/
function TransformEachInToHash(options) {
function TransformEachInToHash(options = {}) {
// set later within HTMLBars to the syntax package
this.syntax = null;
this.options = options || {};
this.options = options;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ import calculateLocationDisplay from 'ember-template-compiler/system/calculate-l
@private
@class TransformInputOnToOnEvent
*/
function TransformInputOnToOnEvent(options) {
function TransformInputOnToOnEvent(options = {}) {
// set later within HTMLBars to the syntax package
this.syntax = null;
this.options = options || {};
this.options = options;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export default function calculateLocationDisplay(moduleName, _loc) {
let loc = _loc || {};
export default function calculateLocationDisplay(moduleName, loc = {}) {
let { column, line } = loc.start || {};
let moduleInfo = '';
if (moduleName) {
Expand Down
3 changes: 1 addition & 2 deletions packages/ember-views/lib/mixins/view_child_views_support.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export default Mixin.create({
@return {Ember.View} new instance
@private
*/
createChildView(maybeViewClass, _attrs) {
createChildView(maybeViewClass, attrs = {}) {
if (!maybeViewClass) {
throw new TypeError('createChildViews first argument must exist');
}
Expand All @@ -92,7 +92,6 @@ export default Mixin.create({
return maybeViewClass;
}

var attrs = _attrs || {};
var view;

attrs.parentView = this;
Expand Down
4 changes: 2 additions & 2 deletions tests/node/component-rendering-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ QUnit.test("Component with dynamic value", function(assert) {
assert.ok(html.match(/<h1>Hello World<\/h1>/));
});

function buildComponent(template, props) {
function buildComponent(template, props = {}) {
var Component = Ember.Component.extend({
renderer: new Ember._Renderer(new DOMHelper(new SimpleDOM.Document())),
layout: compile(template)
}, props || {});
}, props);

return Component.create({
_domHelper: new DOMHelper(new SimpleDOM.Document()),
Expand Down

0 comments on commit 586d4c6

Please sign in to comment.