2016-10-19 15:22:05 +03:00
|
|
|
(ns status-im.network.handlers
|
|
|
|
(:require [re-frame.core :refer [dispatch debug enrich after]]
|
|
|
|
[status-im.utils.handlers :refer [register-handler]]
|
|
|
|
[status-im.utils.handlers :as u]
|
2016-12-27 15:46:06 +02:00
|
|
|
[status-im.network.net-info :as ni]))
|
2016-10-19 15:22:05 +03:00
|
|
|
|
|
|
|
(register-handler :listen-to-network-status!
|
|
|
|
(u/side-effect!
|
|
|
|
(fn []
|
|
|
|
(let [handler #(dispatch [:update-network-status %])]
|
|
|
|
(ni/init handler)
|
|
|
|
(ni/add-listener handler)))))
|
|
|
|
|
|
|
|
(register-handler :update-network-status
|
|
|
|
(fn [db [_ is-connected?]]
|
|
|
|
(let [status (if is-connected? :online :offline)]
|
|
|
|
(assoc db :network-status status))))
|