Skip to content

Commit

Permalink
remove wrap-first-time
Browse files Browse the repository at this point in the history
Signed-off-by: yenda <eric@status.im>
  • Loading branch information
yenda committed Sep 24, 2019
1 parent ebc2ff0 commit 133800b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 25 deletions.
22 changes: 19 additions & 3 deletions TROUBLESHOOTING.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# [DEPRECATED] Undefined is not an object evaluating `register_handler_fx`

## Deprecation note

This type of error should not occur anymore now that we require the namespace in the `fx.cljs` file.

It can however happen with other macros requiring a cljs namespace.

The general fix for that type of issue is to have two files for the namespace where your macros are defined, let's say for `my-project.my-macro` namespace you would have:
- my_macro.cljs in which you need `(:require-macros my-project.my-macro)` and `(:require my-project.the-namespace-used-in-the-macro)`
- my_macro.clj in which you define the macro

That way you don't need to use any magical call like `find-ns` or inline `require` with some kind of call only once switch (which was the root cause of another bug in ``defstyle`` macro because the compilation phase at which the evaluation of the switch is done was not properly considered).

## Stacktrace

Stacktrace:
```
13:25:22, Requiring: hi-base32
13:25:23, Possible Unhandled Promise Rejection (id: 0):
Expand All @@ -18,9 +32,11 @@ _callTimer@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false
_callImmediatesPass@http://localhost:8081/index.bundle?pla<…>
```

Cause:
## Cause

- stacktrace mentions `register_handler_fx`,
- common cause is when requires have been cleaned up and a require of `status-im.utils.handlers` namespace was removed because it looked like it was unused but was actually used through a fx/defn macro

Solution:
## Solution

go through known faulty commit looking for deleted requires
27 changes: 5 additions & 22 deletions src/status_im/utils/styles.clj
Original file line number Diff line number Diff line change
@@ -1,20 +1,5 @@
(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/os\"
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/os 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 :desktop)
Expand All @@ -41,9 +26,8 @@
{:width 100
:height 20}"
[style-name style]
(wrap-first-time
`(def ~style-name
~(body style))))
`(def ~style-name
~(body style)))

(defmacro defnstyle
"Defines style function.
Expand All @@ -62,7 +46,6 @@
{:width 100
:height 5}"
[style-name params style]
(wrap-first-time
`(defn ~style-name
[~@params]
~(body style))))
`(defn ~style-name
[~@params]
~(body style)))
3 changes: 3 additions & 0 deletions src/status_im/utils/styles.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(ns status-im.utils.styles
(:require-macros status-im.utils.fx)
(:require status-im.utils.platform))

0 comments on commit 133800b

Please sign in to comment.