Skip to content

ensure data is up to date when re-rendering yield blocks #720

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

Merged
merged 2 commits into from
Jul 25, 2017
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: 5 additions & 1 deletion src/generators/dom/visitors/Element/Binding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Block from '../../Block';
import { Node } from '../../../../interfaces';
import { State } from '../../interfaces';
import getObject from '../../../../utils/getObject';
import getTailSnippet from '../../../../utils/getTailSnippet';

export default function visitBinding(
generator: DomGenerator,
Expand Down Expand Up @@ -83,8 +84,11 @@ export default function visitBinding(
break;
}`;

const { name } = getObject(attribute.value);
const tailSnippet = getTailSnippet(attribute.value);

updateElement = deindent`
var ${value} = ${snippet};
var ${value} = #component.get( '${name}' )${tailSnippet};
for ( var #i = 0; #i < ${state.parentNode}.options.length; #i += 1 ) {
var ${option} = ${state.parentNode}.options[#i];

Expand Down
20 changes: 20 additions & 0 deletions test/runtime/samples/binding-select-in-yield/Modal.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{{#if !hidden}}
{{ yield }}
{{/if}}

<script>
export default {
data () {
return {
hidden: true
};
},
methods: {
toggle () {
this.set({
hidden: !this.get('hidden')
});
}
}
};
</script>
63 changes: 63 additions & 0 deletions test/runtime/samples/binding-select-in-yield/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
export default {
html: ``,

data: {
letter: 'b'
},

test ( assert, component, target, window ) {
component.refs.modal.toggle();

assert.htmlEqual(target.innerHTML, `
<span>b</span>

<select>
<option value='a'>a</option>
<option value='b'>b</option>
<option value='c'>c</option>
</select>
`);

const select = target.querySelector('select');
const change = new window.MouseEvent('change');

select.options[2].selected = true;
select.dispatchEvent(change);
assert.equal(component.get('letter'), 'c');

assert.deepEqual(Array.from(select.options).map(o => o.selected), [
false,
false,
true
]);

assert.htmlEqual(target.innerHTML, `
<span>c</span>

<select>
<option value='a'>a</option>
<option value='b'>b</option>
<option value='c'>c</option>
</select>
`);

component.refs.modal.toggle();
component.refs.modal.toggle();

assert.deepEqual(Array.from(select.options).map(o => o.selected), [
false,
false,
true
]);

assert.htmlEqual(target.innerHTML, `
<span>c</span>

<select>
<option value='a'>a</option>
<option value='b'>b</option>
<option value='c'>c</option>
</select>
`);
}
};
23 changes: 23 additions & 0 deletions test/runtime/samples/binding-select-in-yield/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<Modal ref:modal>
<span>{{letter}}</span>
<select bind:value='letter'>
{{#each letters as letter}}
<option value="{{letter}}">{{letter}}</option>
{{/each}}
</select>
</Modal>

<script>
import Modal from './Modal.html';

export default {
data () {
return {
letters: ['a', 'b', 'c']
};
},
components: {
Modal
}
};
</script>