Commit 84ba82cc authored by Ricardo J. Mendez's avatar Ricardo J. Mendez

Refactoring initialization and event hook up, expanded comments

Removed unnecessary idle state set - if we're being initialized on load,
we are not idle.  The only reason it was there initially was as a bit of
a hack to ensure we queried the current window when active.
parent 4da3a030
......@@ -54,8 +54,13 @@
don't end up receiving events when we don't yet have the environment
set up to handle them."
(on-channel alarms/on-alarm dispatch-sync ::on-alarm)
(on-channel browser/on-clicked dispatch-sync ::on-clicked-button)
;; We should use dispatch for anything that does not absolutely require
;; immediate handling, to avoid interferring with the regular initialization
;; and event flow. On this case, I' using it only for log-content,
;; which has no effect on app-state, and for on-suspend, which we want to
;; handle immediately.
(on-channel alarms/on-alarm dispatch ::on-alarm)
(on-channel browser/on-clicked dispatch ::on-clicked-button)
(on-channel runtime/on-suspend dispatch-sync :suspend)
(on-channel runtime/on-suspend-canceled dispatch-sync :log-content)
(on-channel tabs/on-activated dispatch ::tab-activated)
......@@ -98,11 +103,11 @@
(fn [_]
(dispatch [:data-load (<! (data/get))])
(dispatch [:data-load (<! (data/load))])
(dispatch [::window-focus {:windowId (:id (<! (windows/get-last-focused {:populate false})))}])
(dispatch [:idle-state-change {:newState (<! (idle/query-state 30))}]))
{:app-state {}
:hookup-done? false}))
;; We should only hook to the channels once, so we do it during the :initialize handler
{:app-state {}}))
......@@ -112,11 +117,8 @@
;; Create a new id if we don't have one
(when (empty? (:instance-id new-data))
(dispatch [:data-set :instance-id (.-uuid (random-uuid))]))
;; Save the data we just imported
(data/set new-data)
;; We should only hook to the channels once.
(when (not (:hookup-done? app-state))
;; Save the data we just received
(data/save new-data)
;; Process the suspend info
(let [suspend-info (:suspend-info new-data)
old-tab (:active-tab suspend-info)
......@@ -128,8 +130,6 @@
(dispatch [:handle-activation old-tab (:start-time old-tab)])
(dispatch [:handle-deactivation old-tab (:time suspend-info)])))
(-> app-state
(assoc-in [:ui-state :section] :time-track)
(assoc :hookup-done? true)
(assoc :data (assoc new-data :suspend-info nil)))))
......@@ -137,7 +137,7 @@
(fn [app-state [_ key item]]
(let [new-state (assoc-in app-state [:data key] item)]
(data/set (:data new-state))
(data/save (:data new-state))
......@@ -5,12 +5,12 @@
(:require-macros [cljs.core.async.macros :refer [go]]))
(defn set
(defn save
"Saves our data block on the extension's storage"
(storage/set {:data (to-transit data)}))
(defn get
(defn load
"Returns a channel where we'll put the entire data block read from the
extension's storage"
......@@ -41,7 +41,7 @@
(defn do-transformations! []
(let [data (<! (data/get))
(let [data (<! (data/load))
nodes (sel :.result_url_heading)
base (sel1 :.web_regular_results)]
(doseq [node nodes]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment