mirror of https://github.com/sveltejs/svelte
commit
d23de6607c
@ -0,0 +1,14 @@
|
||||
export default {
|
||||
html: '<p>50</p>',
|
||||
|
||||
test ( assert, component, target ) {
|
||||
component.set({ range: [ 50, 100 ] });
|
||||
assert.htmlEqual( target.innerHTML, '<p>75</p>' );
|
||||
|
||||
component.set({ range: [ 50, 60 ] });
|
||||
assert.htmlEqual( target.innerHTML, '<p>55</p>' );
|
||||
|
||||
component.set({ x: 8 });
|
||||
assert.htmlEqual( target.innerHTML, '<p>58</p>' );
|
||||
}
|
||||
};
|
@ -0,0 +1,20 @@
|
||||
<p>{{scale(x)}}</p>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data: () => ({
|
||||
x: 5,
|
||||
domain: [ 0, 10 ],
|
||||
range: [ 0, 100 ]
|
||||
}),
|
||||
|
||||
computed: {
|
||||
scale: ( domain, range ) => {
|
||||
return num => {
|
||||
const t = domain[0] + ( num - domain[0] ) / ( domain[1] - domain[0] );
|
||||
return range[0] + t * ( range[1] - range[0] );
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
@ -0,0 +1,8 @@
|
||||
export default {
|
||||
html: '<h1>Hello world!</h1>',
|
||||
|
||||
test ( assert, component, target ) {
|
||||
component.set({ name: () => 'everybody' });
|
||||
assert.htmlEqual( target.innerHTML, '<h1>Hello everybody!</h1>' );
|
||||
}
|
||||
};
|
@ -0,0 +1,9 @@
|
||||
<h1>Hello {{name()}}!</h1>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data: () => ({
|
||||
name: () => 'world'
|
||||
})
|
||||
};
|
||||
</script>
|
Loading…
Reference in new issue