Skip to content

Commit 0dfcb61

Browse files
committed
Optimize phone numbers example code
1 parent 06090e9 commit 0dfcb61

File tree

1 file changed

+31
-46
lines changed

1 file changed

+31
-46
lines changed
Lines changed: 31 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,41 @@
11
<script>
2-
import { onMount, tick } from 'svelte';
3-
import { getTodos } from '../utils/getTodos';
4-
import { format } from '../utils/format';
2+
import { tick } from "svelte";
3+
import { format } from "../utils/format";
54
6-
export let title = "Enter what do you want to do.";
7-
export let buttonTitle = "Add todo";
5+
export let title = "Enter what do you want to do.";
86
9-
let items = [];
7+
let text = "";
8+
async function handleTextChange(event) {
9+
const { selectionStart, selectionEnd, value } = this;
10+
text = format(event.target.value);
1011
11-
onMount(() => {
12-
console.log('onMount');
13-
const get = async () => {
14-
items = await getTodos();
15-
}
16-
get();
17-
});
18-
19-
function handleClick(){
20-
items = [...items, 'item'];
21-
}
22-
23-
let text = '';
24-
async function handleTextChange(event) {
25-
const { selectionStart, selectionEnd, value } = this;
26-
text = format(event.target.value);
27-
28-
await tick();
29-
this.selectionStart = selectionStart;
30-
this.selectionEnd = selectionEnd;
31-
}
32-
12+
await tick();
13+
this.selectionStart = selectionStart;
14+
this.selectionEnd = selectionEnd;
15+
}
3316
</script>
3417

3518
<div class="main-container">
36-
<label for="todo-text">{ title }</label>
37-
<input class="todo-input" id="todo-text" value={text} on:input={handleTextChange} />
38-
<button type="button" on:click={handleClick}>{buttonTitle}</button>
19+
<label for="todo-text">{title}</label>
20+
<input
21+
class="todo-input"
22+
id="todo-text"
23+
value={text}
24+
on:input={handleTextChange}
25+
/>
3926
</div>
4027

41-
{JSON.stringify(items, null, 2)}
42-
4328
<style>
44-
label {
45-
color: cornsilk;
46-
color: blueviolet;
47-
}
48-
.main-container{
49-
background-color: lightseagreen;
50-
border-radius: 5px;
51-
padding: 10px;
52-
}
53-
.todo-input {
54-
width: 100%;
55-
}
56-
</style>
29+
label {
30+
color: cornsilk;
31+
color: blueviolet;
32+
}
33+
.main-container {
34+
background-color: lightseagreen;
35+
border-radius: 5px;
36+
padding: 10px;
37+
}
38+
.todo-input {
39+
width: 100%;
40+
}
41+
</style>

0 commit comments

Comments
 (0)