-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from thoov/controller-link-to
Add link-to with controller support
- Loading branch information
Showing
7 changed files
with
95 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { test } from 'qunit'; | ||
import Controller from '@ember/controller'; | ||
import hbs from 'htmlbars-inline-precompile'; | ||
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance'; | ||
|
||
moduleForAcceptance('Acceptance | {{link-to currentWhen="index"}} & {{#link-to "profile" otherController}}'); | ||
|
||
test('that {{link-to}} helper supports currentWhen', function(assert) { | ||
visit('/about'); | ||
|
||
andThen(function() { | ||
assert.equal(find('#other-link.active').length, 1, 'The link is active since current-when is a parent route'); | ||
}); | ||
}); | ||
|
||
test('that currentWhen will trigger a deprecation', function(assert) { | ||
visit('/about'); | ||
|
||
andThen(function() { | ||
assert.expectDeprecation('Usage of `currentWhen` is deprecated, use `current-when` instead.'); | ||
}); | ||
}); | ||
|
||
test('unwraps controllers', function(assert) { | ||
this.application.register('template:link-to', hbs`{{#link-to 'profile' otherController}}Text{{/link-to}}`); | ||
this.application.register('controller:link-to', Controller.extend({ | ||
otherController: Controller.create({ | ||
model: 'foo' | ||
}) | ||
})); | ||
|
||
let deprecation = /Providing `{{link-to}}` with a param that is wrapped in a controller is deprecated./; | ||
|
||
visit('/link-to'); | ||
|
||
andThen(function() { | ||
assert.expectDeprecation(deprecation); | ||
let text = find('a').text().trim(); | ||
assert.equal(text, 'Text', 'The component is composed correctly'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
(function() { | ||
var _Ember; | ||
if (typeof Ember !== 'undefined') { | ||
_Ember = Ember; | ||
} else { | ||
_Ember = require('ember').default; | ||
} | ||
|
||
const reopenObject = { | ||
currentWhen: _Ember.computed.deprecatingAlias('current-when', { | ||
id: 'ember-routing-view.deprecated-current-when', | ||
until: '3.0.0' | ||
}), | ||
|
||
_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 (_Ember.ControllerMixin.detect(value)) { | ||
_Ember.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; | ||
} | ||
} | ||
|
||
if (EmberENV && EmberENV._ENABLE_CURRENT_WHEN_SUPPORT !== true) { | ||
delete reopenObject['currentWhen']; | ||
} | ||
|
||
if (EmberENV && EmberENV._ENABLE_CONTROLLER_WRAPPED_SUPPORT !== true) { | ||
delete reopenObject['_getModels']; | ||
} | ||
|
||
_Ember.LinkComponent.reopen(reopenObject); | ||
})(); |