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

fix context for bindings #690

Merged
merged 1 commit into from
Jul 7, 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
3 changes: 2 additions & 1 deletion src/generators/dom/visitors/Component/Binding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ export default function visitBinding(
block,
name,
snippet,
context: '_context',
_this: 'this',
props: '_context',
attribute,
dependencies,
value: 'value',
Expand Down
3 changes: 2 additions & 1 deletion src/generators/dom/visitors/Element/Binding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ export default function visitBinding(
block,
name,
snippet,
context: '_svelte',
_this: state.parentNode,
props: '_svelte',
attribute,
dependencies,
value,
Expand Down
2 changes: 1 addition & 1 deletion src/generators/dom/visitors/Element/EventHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export default function visitEventHandler(
// create the handler body
const handlerBody = deindent`
${state.usesComponent &&
`var ${block.alias('component')} = this._svelte.component;`}
`var ${block.alias('component')} = ${_this}._svelte.component;`}
${declarations}
[✂${attribute.expression.start}-${attribute.expression.end}✂];
`;
Expand Down
7 changes: 4 additions & 3 deletions src/generators/dom/visitors/shared/binding/getSetter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ export default function getSetter({
block,
name,
snippet,
context,
_this,
props,
attribute,
dependencies,
value,
Expand All @@ -20,8 +21,8 @@ export default function getSetter({
const computed = isComputed(attribute.value);

return deindent`
var list = this.${context}.${block.listNames.get(name)};
var index = this.${context}.${block.indexNames.get(name)};
var list = ${_this}.${props}.${block.listNames.get(name)};
var index = ${_this}.${props}.${block.indexNames.get(name)};
${computed && `var state = #component.get();`}
list[index]${tail} = ${value};

Expand Down
32 changes: 32 additions & 0 deletions test/runtime/samples/binding-select-in-each-block/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
export default {
skip: true, // JSDOM...

html: `
<select>
<option value='hullo'>Hullo</option>
<option value='world'>World</option>
</select>

<select>
<option value='hullo'>Hullo</option>
<option value='world'>World</option>
</select>
`,

data: {
items: [{ value: 'hullo' }, { value: 'world' }]
},

test(assert, component, target, window) {
const selects = [...target.querySelectorAll('select')];

const change = new window.Event('change');

selects[1].options[0].selected = true;
selects[1].dispatchEvent(change);

assert.deepEqual(component.get('items'), [
{ value: 'hullo' }, { value: 'hullo' }
]);
}
};
6 changes: 6 additions & 0 deletions test/runtime/samples/binding-select-in-each-block/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{{#each items as item}}
<select bind:value="item.value">
<option value="hullo">Hullo</option>
<option value="world">World</option>
</select>
{{/each}}