From 7694ad9e873d80824a07798de66b96b0f6a96dbb Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Fri, 27 May 2016 19:44:06 +0300 Subject: [PATCH] clean js/window first attempt --- src/status_im/components/action_button.cljs | 6 +++--- src/status_im/components/icons/ionicons.cljs | 4 +--- .../components/invertible_scroll_view.cljs | 5 ++--- src/status_im/components/item_checkbox.cljs | 4 +--- src/status_im/components/realm.cljs | 9 -------- src/status_im/components/toolbar.cljs | 4 +--- src/status_im/i18n.cljs | 21 +++++-------------- src/status_im/utils/crypt.cljs | 10 ++++----- src/status_im/utils/listview.cljs | 3 +-- 9 files changed, 19 insertions(+), 47 deletions(-) delete mode 100644 src/status_im/components/realm.cljs diff --git a/src/status_im/components/action_button.cljs b/src/status_im/components/action_button.cljs index db303f5f6d..6ee896d1ed 100644 --- a/src/status_im/components/action_button.cljs +++ b/src/status_im/components/action_button.cljs @@ -1,7 +1,7 @@ (ns status-im.components.action-button (:require [reagent.core :as r])) -(set! js/window.ActionButton (js/require "react-native-action-button")) +(def class (js/require "react-native-action-button")) -(def action-button (r/adapt-react-class (.-default js/ActionButton))) -(def action-button-item (r/adapt-react-class (.. js/ActionButton -default -Item))) \ No newline at end of file +(def action-button (r/adapt-react-class (.-default class))) +(def action-button-item (r/adapt-react-class (.. class -default -Item))) diff --git a/src/status_im/components/icons/ionicons.cljs b/src/status_im/components/icons/ionicons.cljs index 885af057d5..5bc4a06ddc 100644 --- a/src/status_im/components/icons/ionicons.cljs +++ b/src/status_im/components/icons/ionicons.cljs @@ -1,6 +1,4 @@ (ns status-im.components.icons.ionicons (:require [reagent.core :as r])) -(set! js/window.Ionicons (js/require "react-native-vector-icons/Ionicons")) - -(def icon (r/adapt-react-class js/Ionicons)) +(def icon (r/adapt-react-class (js/require "react-native-vector-icons/Ionicons"))) diff --git a/src/status_im/components/invertible_scroll_view.cljs b/src/status_im/components/invertible_scroll_view.cljs index daf873a773..ba4a1d546a 100644 --- a/src/status_im/components/invertible_scroll_view.cljs +++ b/src/status_im/components/invertible_scroll_view.cljs @@ -1,8 +1,7 @@ (ns status-im.components.invertible-scroll-view) -(set! js/window.InvertibleScrollView (js/require "react-native-invertible-scroll-view")) +(def class (js/require "react-native-invertible-scroll-view")) (defn invertible-scroll-view [props] - (js/React.createElement js/InvertibleScrollView - (clj->js (merge {:inverted true} props)))) + (js/React.createElement class (clj->js (merge {:inverted true} props)))) diff --git a/src/status_im/components/item_checkbox.cljs b/src/status_im/components/item_checkbox.cljs index 97d43ecd37..45c667141d 100644 --- a/src/status_im/components/item_checkbox.cljs +++ b/src/status_im/components/item_checkbox.cljs @@ -1,7 +1,5 @@ (ns status-im.components.item-checkbox (:require [reagent.core :as r])) -(set! js/window.ItemCheckbox (js/require "react-native-circle-checkbox")) - -(def item-checkbox (r/adapt-react-class js/ItemCheckbox)) +(def item-checkbox (r/adapt-react-class (js/require "react-native-circle-checkbox"))) diff --git a/src/status_im/components/realm.cljs b/src/status_im/components/realm.cljs deleted file mode 100644 index eff8c1fee5..0000000000 --- a/src/status_im/components/realm.cljs +++ /dev/null @@ -1,9 +0,0 @@ -(ns status-im.components.realm - (:require [reagent.core :as r])) - -(set! js/window.RealmReactNative (js/require "realm/react-native")) - -(def list-view-class (r/adapt-react-class (.-ListView js/RealmReactNative))) - -(defn list-view [props] - [list-view-class (merge {:enableEmptySections true} props)]) diff --git a/src/status_im/components/toolbar.cljs b/src/status_im/components/toolbar.cljs index 3f21fc8a35..0591c1aba1 100644 --- a/src/status_im/components/toolbar.cljs +++ b/src/status_im/components/toolbar.cljs @@ -12,9 +12,7 @@ color-purple text1-color text2-color - toolbar-background1]] - [status-im.components.realm :refer [list-view]] - [reagent.core :as r])) + toolbar-background1]])) (defn toolbar [{:keys [title nav-action hide-nav? action custom-action background-color custom-content style]}] diff --git a/src/status_im/i18n.cljs b/src/status_im/i18n.cljs index 9abde5c46e..4a6157cc23 100644 --- a/src/status_im/i18n.cljs +++ b/src/status_im/i18n.cljs @@ -2,22 +2,11 @@ (:require [status-im.translations.en :as en])) -(set! js/window.I18n (js/require "react-native-i18n")) -(set! (.-fallbacks js/I18n) true) -(set! (.-defaultSeparator js/I18n) "/") +(def i18n (js/require "react-native-i18n")) +(set! (.-fallbacks i18n) true) +(set! (.-defaultSeparator i18n) "/") -(set! (.-translations js.I18n) (clj->js {:en en/translations})) +(set! (.-translations i18n) (clj->js {:en en/translations})) (defn label [path & options] - (.t js/I18n (name path) (clj->js options))) - -(comment - (defn deep-merge [& maps] - (if (every? map? maps) - (apply merge-with deep-merge maps) - (last maps))) - - (defn add-translations [new-translations] - (let [translations (.-translations js/I18n)] - (set! (.-translations js/I18n) (clj->js (deep-merge (js->clj translations) new-translations))))) - ) \ No newline at end of file + (.t i18n (name path) (clj->js options))) diff --git a/src/status_im/utils/crypt.cljs b/src/status_im/utils/crypt.cljs index 722581d10c..87730efe8c 100644 --- a/src/status_im/utils/crypt.cljs +++ b/src/status_im/utils/crypt.cljs @@ -3,7 +3,7 @@ [clojure.string :as s]) (:import goog.crypt.Sha256)) -(set! js/window.RnRandomBytes (js/require "react-native-randombytes")) +(def random-bytes (js/require "react-native-randombytes")) (def sha-256 (Sha256.)) @@ -19,7 +19,7 @@ (byteArrayToHex (.digest sha-256))) (defn gen-random-bytes [length cb] - (.randomBytes js/window.RnRandomBytes length (fn [& [err buf]] - (if err - (cb {:error err}) - (cb {:buffer buf}))))) + (.randomBytes random-bytes length (fn [& [err buf]] + (if err + (cb {:error err}) + (cb {:buffer buf}))))) diff --git a/src/status_im/utils/listview.cljs b/src/status_im/utils/listview.cljs index bd9dfe5dc5..dcd63da8bd 100644 --- a/src/status_im/utils/listview.cljs +++ b/src/status_im/utils/listview.cljs @@ -1,6 +1,5 @@ (ns status-im.utils.listview - (:require-macros [natal-shell.data-source :refer [data-source]]) - (:require [status-im.components.realm])) + (:require-macros [natal-shell.data-source :refer [data-source]])) (defn clone-with-rows [ds rows] (.cloneWithRows ds (reduce (fn [ac el] (.push ac el) ac)