From 0badfd6b5b04cd19f4155ae6a058f567ad94dd02 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Mon, 25 Sep 2017 13:27:03 +0200 Subject: [PATCH] fix Use of undeclared Var status-im.utils.platform/platform warning --- src/status_im/utils/styles.clj | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/status_im/utils/styles.clj b/src/status_im/utils/styles.clj index 783116baab..b32a1a1a4b 100644 --- a/src/status_im/utils/styles.clj +++ b/src/status_im/utils/styles.clj @@ -1,5 +1,20 @@ (ns status-im.utils.styles) +(def first-time (atom true)) + +(defn wrap-first-time + "Allows to avoid + \"Use of undeclared Var status-im.utils.platform/platform\" + warning. When defstyle or defnstyle is called first time status-im.utils.platform + namespace will be explicitly required so that clojurescript compiler will compile + it before using status-im.utils.platform/platform in macro" + [body] + `(do + ~@[(when @first-time + (reset! first-time false) + `(require 'status-im.utils.platform))] + ~body)) + (defn body [style] `(let [style# ~style common# (dissoc style# :android :ios) @@ -26,8 +41,9 @@ {:width 100 :height 20}" [style-name style] - `(def ~style-name - ~(body style))) + (wrap-first-time + `(def ~style-name + ~(body style)))) (defmacro defnstyle "Defines style function. @@ -46,6 +62,7 @@ {:width 100 :height 5}" [style-name params style] - `(defn ~style-name - [~@params] - ~(body style))) + (wrap-first-time + `(defn ~style-name + [~@params] + ~(body style))))