Skip to content

Commit

Permalink
remove clj-bean, use :utils/dispatch-later
Browse files Browse the repository at this point in the history
  • Loading branch information
flexsurfer committed Mar 3, 2020
1 parent 4be9b14 commit 03c4580
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 35 deletions.
55 changes: 26 additions & 29 deletions src/status_im/transport/message/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
[status-im.ethereum.core :as ethereum]
[status-im.native-module.core :as status]
[status-im.ens.core :as ens]
[cljs-bean.core :as clj-bean]
[status-im.utils.fx :as fx]
[taoensso.timbre :as log]
[status-im.ethereum.json-rpc :as json-rpc]))
[status-im.ethereum.json-rpc :as json-rpc]
[status-im.utils.types :as types]))

(defn- js-obj->seq [obj]
;; Sometimes the filter will return a single object instead of a collection
Expand All @@ -42,34 +42,31 @@
(let [chats (.-chats response-js)
contacts (.-contacts response-js)
installations (.-installations response-js)
raw-messages (.-rawMessages response-js)
messages (.-messages response-js)]
(time (cond
(seq installations)
(let [installation (.pop installations)]
(println "installation" installation)
(fx/merge cofx
{:dispatch [::process response-js]}
(models.pairing/handle-installation (js->clj installation :keywordize-keys true))))

(seq contacts)
(let [contact (.pop contacts)]
(println "contact" contact)
(fx/merge cofx
{:dispatch [::process response-js]}
(handle-contact (-> contact (js->clj :keywordize-keys true) (data-store.contacts/<-rpc)))))
(seq chats)
(let [chat (.pop chats)]
(println "chat" chat)
(fx/merge cofx
{:dispatch [::process response-js]}
(handle-chat (-> chat (js->clj :keywordize-keys true) (data-store.chats/<-rpc)))))
(seq messages)
(let [message (.pop messages)]
(println "message" message)
(fx/merge cofx
{:dispatch [::process response-js]}
(handle-message (-> message (js->clj :keywordize-keys true) (data-store.messages/<-rpc)))))))))
(cond
(seq installations)
(let [installation (.pop installations)]
(fx/merge cofx
{:utils/dispatch-later [{:ms 20 :dispatch [::process response-js]}]}
(models.pairing/handle-installation (types/js->clj installation))))

(seq contacts)
(let [contact (.pop contacts)]
(fx/merge cofx
{:utils/dispatch-later [{:ms 20 :dispatch [::process response-js]}]}
(handle-contact (-> contact (types/js->clj) (data-store.contacts/<-rpc)))))

(seq chats)
(let [chat (.pop chats)]
(fx/merge cofx
{:utils/dispatch-later [{:ms 20 :dispatch [::process response-js]}]}
(handle-chat (-> chat (types/js->clj) (data-store.chats/<-rpc)))))

(seq messages)
(let [message (.pop messages)]
(fx/merge cofx
{:utils/dispatch-later [{:ms 20 :dispatch [::process response-js]}]}
(handle-message (-> message (types/js->clj) (data-store.messages/<-rpc))))))))

(handlers/register-handler-fx
::process
Expand Down
2 changes: 0 additions & 2 deletions src/status_im/ui/components/large_toolbar/view.cljs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
(ns status-im.ui.components.large-toolbar.view
(:require [reagent.core :as reagent]
[cljs-bean.core :refer [->clj ->js]]
[status-im.ui.components.list.views :as list.views]
[status-im.ui.components.react :as react]
[status-im.ui.components.toolbar.view :as toolbar]
[status-im.ui.components.large-toolbar.styles :as styles]
[status-im.utils.platform :as platform]
[status-im.ui.components.animation :as animation])
(:require-macros [status-im.utils.views :as views]))

Expand Down
10 changes: 6 additions & 4 deletions src/status_im/utils/types.cljs
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
(ns status-im.utils.types
(:require
[cljs-bean.core :as clj-bean]))
(:refer-clojure :exclude [js->clj]))

(defn to-string [s]
(if (keyword? s)
(name s)
s))

(defn js->clj [data]
(cljs.core/js->clj data :keywordize-keys true))

(defn clj->json [data]
(.stringify js/JSON (clj-bean/->js data)))
(.stringify js/JSON (clj->js data)))

(defn json->clj [json]
(when-not (= json "undefined")
(try
(js->clj (.parse js/JSON json) :keywordize-keys true)
(js->clj (.parse js/JSON json))
(catch js/Error _ (when (string? json) json)))))

(def serialize clj->json)
Expand Down

0 comments on commit 03c4580

Please sign in to comment.