Skip to content

Commit 0393469

Browse files
fpligermadhur-tandon
authored andcommitted
add pydom to todo example
1 parent 4ac33ec commit 0393469

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

todo/main.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from datetime import datetime as dt
22

33
from pyscript import document
4-
4+
from pyweb import pydom
55
tasks = []
66

77

@@ -10,9 +10,12 @@ def q(selector, root=document):
1010

1111

1212
# define the task template that will be use to render new templates to the page
13-
task_template = q("#task-template").content.querySelector(".task")
14-
task_list = q("#list-tasks-container")
15-
new_task_content = q("#new-task-content")
13+
# Note: We use JS element here because pydom doesn't fully support template
14+
# elements now
15+
task_template = pydom.Element(q("#task-template").content.querySelector(".task"))
16+
17+
task_list = pydom["#list-tasks-container"][0]
18+
new_task_content = pydom["#new-task-content"][0]
1619

1720

1821
def add_task(e):
@@ -33,19 +36,20 @@ def add_task(e):
3336

3437
# add the task element to the page as new node in the list by cloning from a
3538
# template
36-
task_html = task_template.cloneNode(True)
39+
task_html = task_template.clone()
3740
task_html.id = task_id
38-
task_html_check = q("input", root=task_html)
39-
task_html_content = q("p", root=task_html)
40-
task_html_content.textContent = task["content"]
41+
42+
task_html_check = task_html.find("input")[0]
43+
task_html_content = task_html.find("p")[0]
44+
task_html_content._js.textContent = task["content"]
4145
task_list.append(task_html)
4246

4347
def check_task(evt=None):
4448
task["done"] = not task["done"]
4549
task_html_content.classList.toggle("line-through", task["done"])
4650

4751
new_task_content.value = ""
48-
task_html_check.onclick = check_task
52+
task_html_check._js.onclick = check_task
4953

5054

5155
def add_task_event(e):

0 commit comments

Comments
 (0)