-
Notifications
You must be signed in to change notification settings - Fork 0
/
debounce.html
41 lines (38 loc) · 1.15 KB
/
debounce.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Patella Example - Debounced Search</title>
<script src="https://cdn.jsdelivr.net/npm/patella@2.2.2"></script>
</head>
<body>
<main>
<h1>Debounced Search</h1>
<input type="text" oninput="model.input = value" placeholder="Enter your debounced search"/>
<h3 id="search"></h3>
</main>
<script>
const $search = document.getElementById("search");
const model = Patella.observe({
input: "",
search: ""
});
Patella.computed(() => {
search.innerText = model.search;
});
let timeoutID;
Patella.computed(() => {
const input = model.input;
if (timeoutID) clearTimeout(timeoutID);
timeoutID = setTimeout(() => {
model.search = input;
}, 1000);
});
</script>
<footer>
<a href="https://github.com/luawtf/Patella/blob/master/examples/debounce.html">View source</a>
</footer>
</body>
</html>