Skip to content

Commit

Permalink
feat: todos.ll is persistent
Browse files Browse the repository at this point in the history
  • Loading branch information
leoshimo committed Feb 29, 2024
1 parent d1049e5 commit 1ffb0da
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions scripts/todos.ll
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@
# todos.ll - Simple TODOs
#

(def todos '())
(def id 0)
(def todos_path "~/todos.ll")

(def (:id id :todos todos) (begin
(def res (try (fread todos_path)))
(if (ok? res) res '(:id 0 :todos ()))))

(defn save_todos ()
"(save_todos) - save current state to file"
(publish :probe (list :id id :todos todos))
(fdump todos_path (list :id id :todos todos)))

(defn next_id ()
"(next_id) - Return the next ID to assign"
Expand All @@ -17,7 +25,8 @@
(set todos (push todos
(list :id id
:title (format "TODO - {}" title)
:on_click (list 'todos_on_click id)))))
:on_click (list 'todos_on_click id))))
(save_todos))

(defn get_todos ()
"(get_todos) - Returns the set of pending todos"
Expand All @@ -26,6 +35,7 @@
(defn todos_on_click (id)
"(todos_on_click ID) - Handle the click on a given todos item with ID"
# filter clicked todos
(set todos (filter todos (fn (it) (not? (contains? it id))))))
(set todos (filter todos (fn (it) (not? (contains? it id)))))
(save_todos))

(spawn_srv :todos :interface '(get_todos add_todo todos_on_click))

0 comments on commit 1ffb0da

Please sign in to comment.