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)
(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))))