fix Use of undeclared Var status-im.utils.platform/platform warning

This commit is contained in:
Roman Volosovskyi 2017-09-25 13:27:03 +02:00
parent 7d9190bb85
commit 0badfd6b5b
1 changed files with 22 additions and 5 deletions

View File

@ -1,5 +1,20 @@
(ns status-im.utils.styles) (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] (defn body [style]
`(let [style# ~style `(let [style# ~style
common# (dissoc style# :android :ios) common# (dissoc style# :android :ios)
@ -26,8 +41,9 @@
{:width 100 {:width 100
:height 20}" :height 20}"
[style-name style] [style-name style]
(wrap-first-time
`(def ~style-name `(def ~style-name
~(body style))) ~(body style))))
(defmacro defnstyle (defmacro defnstyle
"Defines style function. "Defines style function.
@ -46,6 +62,7 @@
{:width 100 {:width 100
:height 5}" :height 5}"
[style-name params style] [style-name params style]
(wrap-first-time
`(defn ~style-name `(defn ~style-name
[~@params] [~@params]
~(body style))) ~(body style))))