Skip to content

Commit

Permalink
Merge pull request #10 from ar90n/feature/use-json-in-todomvc
Browse files Browse the repository at this point in the history
feat: Use json in todomvc example
  • Loading branch information
ar90n authored Apr 30, 2022
2 parents 658b8a4 + 41326ff commit 863019e
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions examples/todomvc/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# ported from https://github.com/tastejs/todomvc/blob/master/examples/elm/src/Main.elm
import functools
import json
from dataclasses import asdict, dataclass, replace
from typing import Any, TypeAlias, Union

Expand All @@ -12,15 +13,15 @@


def save_model(model: "Model") -> None:
local_storage["todos-alfort"] = str(asdict(model))
local_storage["todos-alfort"] = json.dumps(asdict(model))


def load_model() -> "Model":
serialized_model: str | None = local_storage.get("todos-alfort")
if serialized_model is None:
return Model(entries=[], field="", uid=0, visibility="all")

obj = eval(serialized_model)
obj = json.loads(serialized_model)
obj["entries"] = [Entry(**e) for e in obj["entries"]]
return Model(**obj)

Expand Down

0 comments on commit 863019e

Please sign in to comment.