use account-update function instead of dispatching :account-update (#1995)

* use account-update function instead of dispatching :account-update
* add (inject-cofx :now) to default interceptors
This commit is contained in:
Roman Volosovskyi 2017-10-03 17:06:12 +02:00 committed by GitHub
parent 7540dda41d
commit 2763c87c40
6 changed files with 19 additions and 16 deletions

View File

@ -113,7 +113,7 @@
;; TODO(janherich) remove this once send-message events are refactored
(handlers/register-handler-fx
:invoke-console-command-handler!
[re-frame/trim-v (re-frame/inject-cofx :random-id) (re-frame/inject-cofx :now)]
[re-frame/trim-v (re-frame/inject-cofx :random-id)]
(fn [cofx [{:keys [chat-id command] :as command-params}]]
(let [fx-fn (get console-commands->fx (-> command :command :name))]
(-> cofx

View File

@ -390,7 +390,7 @@
(handlers/register-handler-fx
:proceed-command
[re-frame/trim-v (re-frame/inject-cofx :random-id) (re-frame/inject-cofx :now)]
[re-frame/trim-v (re-frame/inject-cofx :random-id)]
(fn [{:keys [db random-id now]} [content]]
(proceed-command db content random-id now)))
@ -465,7 +465,7 @@
(handlers/register-handler-fx
:send-current-message
[(re-frame/inject-cofx :random-id) (re-frame/inject-cofx :now)]
[(re-frame/inject-cofx :random-id)]
(fn [{{:keys [current-chat-id current-public-key] :as db} :db message-id :random-id current-time :now} _]
(let [input-text (get-in db [:chats current-chat-id :input-text])
chat-command (-> db

View File

@ -105,7 +105,7 @@
(handlers/register-handler-fx
::contacts-synced
[re-frame/trim-v (re-frame/inject-cofx :random-id) (re-frame/inject-cofx :now)]
[re-frame/trim-v (re-frame/inject-cofx :random-id)]
(fn [{:keys [db random-id] :as cofx} [contacts]]
(-> db
(contacts-events/add-contacts contacts)

View File

@ -166,7 +166,7 @@
[{{:keys [network]
:accounts/keys [accounts current-account-id] :as db} :db now :now} new-account-fields]
(let [current-account (get accounts current-account-id)
new-account (update-account current-account new-account-fields now)]
new-account (update-account current-account new-account-fields now)]
{:db (assoc-in db [:accounts/accounts current-account-id] new-account)
::save-account new-account
::broadcast-account-update (merge
@ -177,13 +177,13 @@
;; TODO(janherich): remove this event once it's not used anymore
(handlers/register-handler-fx
:account-update
[(re-frame/inject-cofx :now) re-frame/trim-v]
[re-frame/trim-v]
(fn [cofx [new-account-fields]]
(account-update cofx new-account-fields)))
(handlers/register-handler-fx
:account-update-keys
[(re-frame/inject-cofx :get-new-keypair!) (re-frame/inject-cofx :now)]
[(re-frame/inject-cofx :get-new-keypair!)]
(fn [{:keys [db keypair now]} _]
(let [{:accounts/keys [accounts current-account-id]} db
{:keys [public private]} keypair
@ -200,7 +200,6 @@
(handlers/register-handler-fx
:send-account-update-if-needed
[(re-frame/inject-cofx :now)]
(fn [{{:accounts/keys [accounts current-account-id]} :db now :now :as cofx} _]
(let [{:keys [last-updated]} (get accounts current-account-id)
needs-update? (> (- now last-updated) time/week)]

View File

@ -2,7 +2,8 @@
(:require [re-frame.core :refer [dispatch dispatch-sync after] :as re-frame]
[status-im.utils.handlers :refer [register-handler] :as handlers]
[status-im.data-store.networks :as networks]
[status-im.ui.screens.network-settings.navigation]))
[status-im.ui.screens.network-settings.navigation]
[status-im.ui.screens.accounts.events :as accounts-events]))
;;;; FX
@ -28,6 +29,6 @@
(handlers/register-handler-fx
:connect-network
(fn [_ [_ network]]
{:dispatch-n [[:account-update {:network network}]
[:navigate-to-clean :accounts]]}))
(fn [cofx [_ network]]
(merge (accounts-events/account-update cofx {:network network})
{:dispatch [:navigate-to-clean :accounts]})))

View File

@ -1,7 +1,7 @@
(ns status-im.utils.handlers
(:require [cljs.spec.alpha :as spec]
[clojure.string :as string]
[re-frame.core :refer [reg-event-db reg-event-fx]]
[re-frame.core :refer [reg-event-db reg-event-fx] :as re-frame]
[re-frame.interceptor :refer [->interceptor get-coeffect get-effect]]
[taoensso.timbre :as log])
(:require-macros status-im.utils.handlers))
@ -40,15 +40,18 @@
([name middleware handler]
(reg-event-db name [debug-handlers-names (when js/goog.DEBUG check-spec) middleware] handler)))
(def default-interceptors
[debug-handlers-names (when js/goog.DEBUG check-spec) (re-frame/inject-cofx :now)])
(defn register-handler-db
([name handler] (register-handler-db name nil handler))
([name interceptors handler]
(reg-event-db name [debug-handlers-names (when js/goog.DEBUG check-spec) interceptors] handler)))
(reg-event-db name [default-interceptors interceptors] handler)))
(defn register-handler-fx
([name handler] (register-handler-fx name nil handler))
([name interceptors handler]
(reg-event-fx name [debug-handlers-names (when js/goog.DEBUG check-spec) interceptors] handler)))
(reg-event-fx name [default-interceptors interceptors] handler)))
(defn get-hashtags [status]
(if status