Skip to content

Commit

Permalink
[BUGFIX beta] Fix rerendering contextual components when invoked with…
Browse files Browse the repository at this point in the history
… dot

syntax and in block form

Block form of components does not use the same hooks as the other invocations.
A bit of preprocessing is needed to invalidate it and cause a rerender.

Fixes #12678
  • Loading branch information
Serabe committed Dec 3, 2015
1 parent 3d1cf7b commit 4bb5ee4
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 11 deletions.
44 changes: 33 additions & 11 deletions packages/ember-htmlbars/lib/hooks/link-render-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@
import subscribe from 'ember-htmlbars/utils/subscribe';
import { isArray } from 'ember-runtime/utils';
import { chain, read, isStream, addDependency } from 'ember-metal/streams/utils';
import { CONTAINS_DOT_CACHE } from 'ember-htmlbars/system/lookup-helper';
import {
COMPONENT_HASH,
isComponentCell,
mergeInNewHash
} from 'ember-htmlbars/keywords/closure-component';

export default function linkRenderNode(renderNode, env, scope, path, params, hash) {
if (renderNode.streamUnsubscribers) {
return true;
}

var keyword = env.hooks.keywords[path];
let keyword = env.hooks.keywords[path];
if (keyword && keyword.link) {
keyword.link(renderNode.getState(), params, hash);
} else {
Expand All @@ -24,14 +30,30 @@ export default function linkRenderNode(renderNode, env, scope, path, params, has
}
}

// If has a dot in the path, we need to subscribe to the arguments in the
// closure component as well.

if (CONTAINS_DOT_CACHE.get(path)) {
let stream = env.hooks.get(env, scope, path);
let componentCell = stream.value();

if (isComponentCell(componentCell)) {
let closureAttrs = mergeInNewHash(componentCell[COMPONENT_HASH], hash);

for (let key in closureAttrs) {
subscribe(renderNode, env, scope, closureAttrs[key]);
}
}
}

if (params && params.length) {
for (var i = 0; i < params.length; i++) {
for (let i = 0; i < params.length; i++) {
subscribe(renderNode, env, scope, params[i]);
}
}

if (hash) {
for (var key in hash) {
for (let key in hash) {
subscribe(renderNode, env, scope, hash[key]);
}
}
Expand All @@ -43,9 +65,9 @@ export default function linkRenderNode(renderNode, env, scope, path, params, has
}

function eachParam(list) {
var listChange = getKey(list, '[]');
let listChange = getKey(list, '[]');

var stream = chain(list, function() {
let stream = chain(list, function() {
read(listChange);
return read(list);
}, 'each');
Expand All @@ -55,13 +77,13 @@ function eachParam(list) {
}

function shouldDisplay(predicate) {
var length = getKey(predicate, 'length');
var isTruthy = getKey(predicate, 'isTruthy');
let length = getKey(predicate, 'length');
let isTruthy = getKey(predicate, 'isTruthy');

var stream = chain(predicate, function() {
var predicateVal = read(predicate);
var lengthVal = read(length);
var isTruthyVal = read(isTruthy);
let stream = chain(predicate, function() {
let predicateVal = read(predicate);
let lengthVal = read(length);
let isTruthyVal = read(isTruthy);

if (isArray(predicateVal)) {
return lengthVal > 0;
Expand Down
26 changes: 26 additions & 0 deletions packages/ember-htmlbars/tests/helpers/closure_component_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,32 @@ if (isEnabled('ember-contextual-components')) {
'greeting is bound');
});

QUnit.test('updates when curried hash arguments is bound in block form', function() {
owner.register(
'template:components/-looked-up',
compile(`{{greeting}}`)
);

let template = compile(
`{{#with (hash comp=(component "-looked-up" greeting=greeting)) as |my|}}
{{#my.comp}}{{/my.comp}}
{{/with}}`
);

component = Component.extend({
[OWNER]: owner,
template
}).create();

runAppend(component);
equal(component.$().text().trim(), '', '-looked-up component rendered');
run(() => {
component.set('greeting', 'Hodi');
});
equal(component.$().text().trim(), `Hodi`,
'greeting is bound');
});

QUnit.test('nested components overwrites named positional parameters', function() {
let LookedUp = Component.extend();
LookedUp.reopenClass({
Expand Down

0 comments on commit 4bb5ee4

Please sign in to comment.