Skip to content

Commit

Permalink
Merge pull request #12546 from nathanhammond/patch-1
Browse files Browse the repository at this point in the history
[BUGFIX beta] Set models array length in link-to.
  • Loading branch information
mixonic committed Nov 5, 2015
2 parents 341a325 + 7141e35 commit 867ca6a
Showing 1 changed file with 27 additions and 18 deletions.
45 changes: 27 additions & 18 deletions packages/ember-routing-views/lib/components/link-to.js
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,29 @@ let LinkComponent = EmberComponent.extend({
return true;
}),

_getModels(params) {
let modelCount = params.length - 1;
let models = new Array(modelCount);

for (let i = 0; i < modelCount; i++) {
let value = params[i + 1];

while (ControllerMixin.detect(value)) {
deprecate(
'Providing `{{link-to}}` with a param that is wrapped in a controller is deprecated. ' +
(this.parentView ? 'Please update `' + this.parentView + '` to use `{{link-to "post" someController.model}}` instead.' : ''),
false,
{ id: 'ember-routing-views.controller-wrapped-param', until: '3.0.0' }
);
value = value.get('model');
}

models[i] = value;
}

return models;
},

/**
The default href value to use while a link-to is loading.
Only applies when tagName is 'a'
Expand Down Expand Up @@ -769,25 +792,11 @@ let LinkComponent = EmberComponent.extend({
this.set('queryParams', queryParams);

// 4. Any remaining indices (excepting `targetRouteName` at 0) are `models`.
let models = [];

for (let i = 1; i < params.length; i++) {
let value = params[i];

while (ControllerMixin.detect(value)) {
deprecate(
'Providing `{{link-to}}` with a param that is wrapped in a controller is deprecated. ' +
(this.parentView ? 'Please update `' + this.parentView + '` to use `{{link-to "post" someController.model}}` instead.' : ''),
false,
{ id: 'ember-routing-views.controller-wrapped-param', until: '3.0.0' }
);
value = value.get('model');
}

models.push(value);
if (params.length > 1) {
this.set('models', this._getModels(params));
} else {
this.set('models', []);
}

this.set('models', models);
}
});

Expand Down

0 comments on commit 867ca6a

Please sign in to comment.