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 release] Ensure local state can shadow attrs. #11572

Merged
merged 1 commit into from
Jun 28, 2015
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions packages/ember-htmlbars/lib/hooks/get-root.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ function getKey(scope, key) {

var self = scope.self || scope.locals.view;

if (scope.attrs && key in scope.attrs) {
if (self) {
return self.getKey(key);
} else if (scope.attrs && key in scope.attrs) {
// TODO: attrs
// Ember.deprecate("You accessed the `" + key + "` attribute directly. Please use `attrs." + key + "` instead.");
return scope.attrs[key];
} else if (self) {
return self.getKey(key);
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/ember-htmlbars/lib/templates/legacy-each.hbs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{~#each view._arrangedContent -legacy-keyword=keyword as |item|~}}
{{~#if keyword}}
{{~#each view._arrangedContent -legacy-keyword=view.keyword as |item|~}}
{{~#if view.keyword}}
{{~#if attrs.itemViewClass~}}
{{~#view attrs.itemViewClass _defaultTagName=view._itemTagName~}}
{{~legacy-yield item~}}
Expand Down
84 changes: 84 additions & 0 deletions packages/ember-htmlbars/tests/integration/attrs_lookup_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import Registry from 'container/registry';
import compile from 'ember-template-compiler/system/compile';
import ComponentLookup from 'ember-views/component_lookup';
import Component from 'ember-views/views/component';
import { runAppend, runDestroy } from 'ember-runtime/tests/utils';
import EmberView from 'ember-views/views/view';

var registry, container, view;

QUnit.module('component - attrs lookup', {
setup() {
registry = new Registry();
container = registry.container();
registry.optionsForType('component', { singleton: false });
registry.optionsForType('view', { singleton: false });
registry.optionsForType('template', { instantiate: false });
registry.register('component-lookup:main', ComponentLookup);
},

teardown() {
runDestroy(container);
runDestroy(view);
registry = container = view = null;
}
});

QUnit.test('should be able to lookup attrs without `attrs.` - template access', function() {
registry.register('template:components/foo-bar', compile('{{first}}'));

view = EmberView.extend({
template: compile('{{foo-bar first="first attr"}}'),
container: container
}).create();

runAppend(view);

equal(view.$().text(), 'first attr');
});

QUnit.test('should be able to lookup attrs without `attrs.` - component access', function() {
var component;

registry.register('component:foo-bar', Component.extend({
init() {
this._super(...arguments);
component = this;
}
}));

view = EmberView.extend({
template: compile('{{foo-bar first="first attr"}}'),
container: container
}).create();

runAppend(view);

equal(component.get('first'), 'first attr');
});

QUnit.test('should be able to modify a provided attr into local state #11571 / #11559', function() {
var component;

registry.register('component:foo-bar', Component.extend({
init() {
this._super(...arguments);
component = this;
},

didReceiveAttrs() {
this.set('first', this.getAttr('first').toUpperCase());
}
}));
registry.register('template:components/foo-bar', compile('{{first}}'));

view = EmberView.extend({
template: compile('{{foo-bar first="first attr"}}'),
container: container
}).create();

runAppend(view);

equal(view.$().text(), 'FIRST ATTR', 'template lookup uses local state');
equal(component.get('first'), 'FIRST ATTR', 'component lookup uses local state');
});