From ab72105e20626a8d614674ab434aafab52ac3922 Mon Sep 17 00:00:00 2001 From: Sergio Arbeo Date: Thu, 19 Nov 2015 21:30:27 +0530 Subject: [PATCH] [BUGFIX beta] Fix processing arguments in rerender Rerendering a dot-syntax closure component failed to update the attributes due to the shortcut being done too soon. Fix #12613 --- .../ember-htmlbars/lib/hooks/component.js | 13 +++--- .../tests/helpers/closure_component_test.js | 45 +++++++++++++++++++ 2 files changed, 52 insertions(+), 6 deletions(-) diff --git a/packages/ember-htmlbars/lib/hooks/component.js b/packages/ember-htmlbars/lib/hooks/component.js index fe589b35b5f..1e8fc139e21 100644 --- a/packages/ember-htmlbars/lib/hooks/component.js +++ b/packages/ember-htmlbars/lib/hooks/component.js @@ -22,12 +22,6 @@ var IS_ANGLE_CACHE = new Cache(1000, function(key) { export default function componentHook(renderNode, env, scope, _tagName, params, attrs, templates, visitor) { var state = renderNode.getState(); - // Determine if this is an initial render or a re-render - if (state.manager) { - state.manager.rerender(env, attrs, visitor); - return; - } - let tagName = _tagName; if (CONTAINS_DOT_CACHE.get(tagName)) { let stream = env.hooks.get(env, scope, tagName); @@ -53,6 +47,13 @@ export default function componentHook(renderNode, env, scope, _tagName, params, } } + // Determine if this is an initial render or a re-render + if (state.manager) { + state.manager.rerender(env, attrs, visitor); + return; + } + + let isAngleBracket = false; let isTopLevel = false; let isDasherized = false; diff --git a/packages/ember-htmlbars/tests/helpers/closure_component_test.js b/packages/ember-htmlbars/tests/helpers/closure_component_test.js index dde15a187f1..4d796fe7081 100644 --- a/packages/ember-htmlbars/tests/helpers/closure_component_test.js +++ b/packages/ember-htmlbars/tests/helpers/closure_component_test.js @@ -456,6 +456,51 @@ if (isEnabled('ember-contextual-components')) { equal(component.$().text(), `${expectedText},Hola`, '-looked-up component rendered with rest params'); }); + QUnit.test('renders with dot path and updates attributes', function() { + owner.register( + 'component:my-nested-component', + Component.extend({ + didReceiveAttrs() { + this.set('myProp', this.getAttr('my-parent-attr')); + } + }) + ); + + owner.register( + 'template:components/my-nested-component', + compile(`{{myProp}}`) + ); + + owner.register( + 'template:components/my-component', + compile(`{{yield (hash my-nested-component=(component 'my-nested-component' my-parent-attr=attrs.my-attr))}}`) + ); + + let template = compile(`{{#my-component my-attr=myProp as |api|}} + {{api.my-nested-component}} + {{/my-component}} +
+ `); + component = Component.extend({ + [OWNER]: owner, + template, + myProp: 1, + actions: { + changeValue() { this.incrementProperty(`myProp`); } + } + }).create({ }); + + runAppend(component); + + component.$('button').click(); + + equal(component.$('#nested-prop').text(), '2', 'value got updated'); + + component.$('button').click(); + + equal(component.$('#nested-prop').text(), '3', 'value got updated again'); + }); + QUnit.test('adding parameters to a closure component\'s instance does not add it to other instances', function(assert) { owner.register( 'template:components/select-box',