Commit 4eac6eab authored by Ricardo J. Mendez's avatar Ricardo J. Mendez

Revert "Updating re-frame handlers when they are eventful"

Found some bugs while testing #5. See #6 for details.

This reverts commit 641ea302.
parent f2019a95
......@@ -14,7 +14,7 @@
[khroma.tabs :as tabs]
[khroma.runtime :as runtime]
[khroma.windows :as windows]
[re-frame.core :refer [dispatch reg-event-db reg-event-fx subscribe dispatch-sync]]
[re-frame.core :refer [dispatch reg-event-db subscribe dispatch-sync]]
[khroma.extension :as ext]
[khroma.browser-action :as browser]
[khroma.storage :as storage])
......@@ -215,17 +215,17 @@
app-state)))
(reg-event-fx
(reg-event-db
:handle-deactivation
(fn
;; We get two parameters: the tab, and optionally the time at which it
;; was deactivated (which defaults to now)
[_ [_ tab end-time]]
[app-state [_ tab end-time]]
; (console/trace " Deactivating " tab)
(when (pos? (:start-time tab))
(dispatch [:track-time tab (- (or end-time (now))
(:start-time tab))]))
nil))
app-state))
(reg-event-db
......@@ -253,35 +253,35 @@
(reg-event-fx
(reg-event-db
::on-alarm
(fn [{:keys [db]} [_ {:keys [alarm]}]]
(fn [app-state [_ {:keys [alarm]}]]
(when (= window-alarm (:name alarm))
(check-window-status (:active-tab db)))
nil))
(check-window-status (:active-tab app-state)))
app-state))
(reg-event-db
::on-clicked-button
(fn [{:keys [db]} [_ {:keys [tab]}]]
(fn [app-state [_ {:keys [tab]}]]
;; Force it to track the time up until now
(let [active-tab (:active-tab db)]
(let [active-tab (:active-tab app-state)]
(dispatch [:handle-deactivation active-tab])
(dispatch [:handle-activation active-tab]))
(dispatch [:on-relevance-sort-tabs tab])
nil))
app-state))
(reg-event-fx
(reg-event-db
::on-clicked-menu
(fn [_ [_ {:keys [info tab]}]]
(fn [app-state [_ {:keys [info tab]}]]
(dispatch [(keyword (:menuItemId info)) tab])
nil))
app-state))
(reg-event-fx
(reg-event-db
::on-message
(fn [+ [_ payload]]
(fn [app-state [_ payload]]
(let [{:keys [message sender]} (keywordize-keys payload)
{:keys [action data]} message]
; (console/log "GOT INTERNAL MESSAGE" message "from" sender)
......@@ -289,31 +289,31 @@
:reload-data (go (dispatch [:data-load (<! (io/load :data)) (<! (io/load :settings))]))
:delete-url (dispatch [:delete-url data])
(console/error "Nothing matched" message)))
nil))
app-state))
(reg-event-fx
(reg-event-db
:on-relevance-show-data
(fn [_ _]
(fn [app-state [_]]
(open-results-tab)
nil))
app-state))
(reg-event-fx
(reg-event-db
:on-relevance-sort-tabs
(fn [{:keys [db]} [_ tab]]
(sort-tabs! (:windowId tab) db)
nil))
(fn [app-state [_ tab]]
(sort-tabs! (:windowId tab) app-state)
app-state))
(reg-event-fx
(reg-event-db
:suspend
;; The message itself is not relevant, we only care that we are being suspended
(fn [{:keys [db]} _]
(fn [app-state [_]]
(dispatch [:data-set :suspend-info {:time (now)
:active-tab (:active-tab db)}])
nil))
:active-tab (:active-tab app-state)}])
app-state))
(reg-event-db
......
(ns relevance.shared-handlers
(:require [khroma.log :as console]
[re-frame.core :refer [reg-event-fx]]))
[re-frame.core :refer [reg-event-db]]))
(reg-event-fx
(reg-event-db
:log-content
(fn [_ [_ content]]
(fn [app-state [_ content]]
(console/log "Log event:" content)
nil
app-state
))
......@@ -176,7 +176,7 @@
"")]])))
;; TODO: We could actually move modal-confirm to a component namespace, parametrize it.
;; We could actually move modal-confirm to a component namespace, parametrize it.
(defn modal-confirm []
(let [modal-info (subscribe [:ui-state :modal-info])
;; On the next one, we can't use not-empty because (= nil (not-empty nil)), and :show expects true/false,
......@@ -288,6 +288,8 @@
(list-urls @list-shown @site-times)]]]]])))
(defn div-sitetimes []
(let [site-times (subscribe [:data :site-times])
sites (reaction (vals @site-times))
......
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