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

[BUGFIX beta] Set models array length in link-to. #12546

Merged
merged 1 commit into from
Nov 5, 2015
Merged
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
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