Add simulation

This commit is contained in:
Icaro Motta 2024-12-23 16:45:04 -03:00
parent 23d3a2db2a
commit 9e2f590e3c
No known key found for this signature in database
GPG Key ID: 009557D9D014DF07
1 changed files with 55 additions and 0 deletions

View File

@ -391,3 +391,58 @@
(re-frame/subscribe [:chats/chat chat-id]))
:->
:image)
(comment
;; Create a large list of chats
(def total-chats 200)
(def chat' (first (vals (:chats @re-frame.db/app-db))))
(let [new-chats (->> (repeat total-chats chat')
(map (fn [chat]
(-> chat
(assoc :chat-id (str (random-uuid)))
(assoc-in [:last-message :content :text]
(str "Initial " (str (random-uuid)))))))
(utils.collection/index-by :chat-id))]
(swap! re-frame.db/app-db assoc
:chats new-chats
:chats-home-list (set (keys new-chats))))
;; Check the update works for one.
(swap! re-frame.db/app-db assoc-in
[:chats
(:chat-id (nth (vals (:chats @re-frame.db/app-db)) 0))
:last-message
:content
:text]
(str (rand-int 10000)))
;; Randomly update individual chats.
(def interval-id
(atom
(js/setInterval
(fn []
(let [chats (vals (:chats @re-frame.db/app-db))
rand-index (rand-int (dec (count chats)))
rand-chat (nth chats rand-index)]
(swap! re-frame.db/app-db
(fn [db]
(-> db
(assoc-in [:chats
(:chat-id rand-chat)
:last-message
:content
:text]
(str (rand-int 10000)))
(assoc-in [:chats
(:chat-id rand-chat)
:timestamp]
(utils.datetime/timestamp)))))))
;; Exagerate the frequency of updates, but even longer delays will cause problems in
;; `develop`.
1000)))
(do
(js/clearInterval @interval-id)
(reset! interval-id nil))
)