-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BUGFIX release] Ensure local state can shadow attrs.
We initially intended to deprecate access to local state (ala proxying to attrs) at this location, but we have decided to hold off on that deprecation until angle bracked component invocation is available. Later in the integration efforts, we added an AttrsProxy to handle most of this functionality for us (when using a View inheritor). In the future, the deprecation will almost certainly be added in the `AttrsProxy` (not `getRoot` hook). --- Prior to this change local state could never use the same name as a value in `attrs` (because the `attrs` always "won"). The else case is still present, when a given template is not backed by a view/component instance.
- Loading branch information
Showing
3 changed files
with
89 additions
and
5 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
84 changes: 84 additions & 0 deletions
84
packages/ember-htmlbars/tests/integration/attrs_lookup_test.js
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,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'); | ||
}); |