mirror of https://github.com/sveltejs/svelte
Merge pull request #605 from sveltejs/gh-602
support binding to computed member expressionspull/613/head
commit
66a1fd76dd
@ -0,0 +1,8 @@
|
||||
{
|
||||
"message": "Cannot bind to rvalue",
|
||||
"pos": 19,
|
||||
"loc": {
|
||||
"line": 1,
|
||||
"column": 19
|
||||
}
|
||||
}
|
@ -0,0 +1 @@
|
||||
<input bind:value='a + b'>
|
@ -0,0 +1,55 @@
|
||||
export default {
|
||||
data: {
|
||||
prop: 'bar',
|
||||
obj: {
|
||||
foo: 'a',
|
||||
bar: 'b',
|
||||
baz: 'c'
|
||||
}
|
||||
},
|
||||
|
||||
html: `
|
||||
<input>
|
||||
<pre>{"foo":"a","bar":"b","baz":"c"}</pre>
|
||||
`,
|
||||
|
||||
test ( assert, component, target, window ) {
|
||||
const input = target.querySelector( 'input' );
|
||||
const event = new window.Event( 'input' );
|
||||
|
||||
assert.equal( input.value, 'b' );
|
||||
|
||||
// edit bar
|
||||
input.value = 'e';
|
||||
input.dispatchEvent( event );
|
||||
|
||||
assert.htmlEqual( target.innerHTML, `
|
||||
<input>
|
||||
<pre>{"foo":"a","bar":"e","baz":"c"}</pre>
|
||||
` );
|
||||
|
||||
// edit baz
|
||||
component.set({ prop: 'baz' });
|
||||
assert.equal( input.value, 'c' );
|
||||
|
||||
input.value = 'f';
|
||||
input.dispatchEvent( event );
|
||||
|
||||
assert.htmlEqual( target.innerHTML, `
|
||||
<input>
|
||||
<pre>{"foo":"a","bar":"e","baz":"f"}</pre>
|
||||
` );
|
||||
|
||||
// edit foo
|
||||
component.set({ prop: 'foo' });
|
||||
assert.equal( input.value, 'a' );
|
||||
|
||||
input.value = 'd';
|
||||
input.dispatchEvent( event );
|
||||
|
||||
assert.htmlEqual( target.innerHTML, `
|
||||
<input>
|
||||
<pre>{"foo":"d","bar":"e","baz":"f"}</pre>
|
||||
` );
|
||||
}
|
||||
};
|
@ -0,0 +1,2 @@
|
||||
<input bind:value='obj[prop]'>
|
||||
<pre>{{JSON.stringify(obj)}}</pre>
|
@ -0,0 +1,30 @@
|
||||
export default {
|
||||
data: {
|
||||
prop: 'name',
|
||||
user: {
|
||||
name: 'alice'
|
||||
}
|
||||
},
|
||||
|
||||
html: `<input>\n<p>hello alice</p>`,
|
||||
|
||||
test ( assert, component, target, window ) {
|
||||
const input = target.querySelector( 'input' );
|
||||
|
||||
assert.equal( input.value, 'alice' );
|
||||
|
||||
const event = new window.Event( 'input' );
|
||||
|
||||
input.value = 'bob';
|
||||
input.dispatchEvent( event );
|
||||
|
||||
assert.equal( target.innerHTML, `<input>\n<p>hello bob</p>` );
|
||||
|
||||
const user = component.get( 'user' );
|
||||
user.name = 'carol';
|
||||
|
||||
component.set({ user });
|
||||
assert.equal( input.value, 'carol' );
|
||||
assert.equal( target.innerHTML, `<input>\n<p>hello carol</p>` );
|
||||
}
|
||||
};
|
@ -0,0 +1,2 @@
|
||||
<input bind:value='user[prop]'>
|
||||
<p>hello {{user.name}}</p>
|
@ -0,0 +1,55 @@
|
||||
export default {
|
||||
data: {
|
||||
prop: 'bar',
|
||||
objects: [{
|
||||
foo: 'a',
|
||||
bar: 'b',
|
||||
baz: 'c'
|
||||
}]
|
||||
},
|
||||
|
||||
html: `
|
||||
<input>
|
||||
<pre>{"foo":"a","bar":"b","baz":"c"}</pre>
|
||||
`,
|
||||
|
||||
test ( assert, component, target, window ) {
|
||||
const input = target.querySelector( 'input' );
|
||||
const event = new window.Event( 'input' );
|
||||
|
||||
assert.equal( input.value, 'b' );
|
||||
|
||||
// edit bar
|
||||
input.value = 'e';
|
||||
input.dispatchEvent( event );
|
||||
|
||||
assert.htmlEqual( target.innerHTML, `
|
||||
<input>
|
||||
<pre>{"foo":"a","bar":"e","baz":"c"}</pre>
|
||||
` );
|
||||
|
||||
// edit baz
|
||||
component.set({ prop: 'baz' });
|
||||
assert.equal( input.value, 'c' );
|
||||
|
||||
input.value = 'f';
|
||||
input.dispatchEvent( event );
|
||||
|
||||
assert.htmlEqual( target.innerHTML, `
|
||||
<input>
|
||||
<pre>{"foo":"a","bar":"e","baz":"f"}</pre>
|
||||
` );
|
||||
|
||||
// edit foo
|
||||
component.set({ prop: 'foo' });
|
||||
assert.equal( input.value, 'a' );
|
||||
|
||||
input.value = 'd';
|
||||
input.dispatchEvent( event );
|
||||
|
||||
assert.htmlEqual( target.innerHTML, `
|
||||
<input>
|
||||
<pre>{"foo":"d","bar":"e","baz":"f"}</pre>
|
||||
` );
|
||||
}
|
||||
};
|
@ -0,0 +1,4 @@
|
||||
{{#each objects as obj}}
|
||||
<input bind:value='obj[prop]'>
|
||||
<pre>{{JSON.stringify(obj)}}</pre>
|
||||
{{/each}}
|
Loading…
Reference in new issue