Skip to content

Commit

Permalink
[#357 #247] Fix for React Native (@currentoor)
Browse files Browse the repository at this point in the history
  • Loading branch information
currentoor authored and ptaoussanis committed May 25, 2020
1 parent 9bb09ac commit 47c4e7d
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions src/taoensso/sente.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -980,15 +980,28 @@
[1] Ref. https://www.npmjs.com/package/websocket
[2] Ref. https://github.com/RyanMcG/lein-npm"
(delay ; Eager eval causes issues with React Native, Ref. #247,
(elide-require
(when (and node-target? (exists? js/require))
(try
(js/require "websocket")
;; In particular, catch 'UnableToResolveError'
(catch :default e
;; (errorf e "Unable to load npm websocket lib")
nil)))))))

;; This `let` silliness intended to work around React Native's
;; static analysis tool, to prevent it from detecting a
;; missing package.
;;
;; Ref. https://github.com/ptaoussanis/sente/issues/247#issuecomment-555219121
;;
(let [make-package-name (fn [prefix] (str prefix "socket"))
require-fn
(if (exists? js/require)
js/require
(constantly :no-op))]

(delay ; Eager eval causes issues with React Native, Ref. #247,
(elide-require ; TODO is this now safe to remove?
(when (and node-target? (exists? js/require))
(try
(require-fn (make-package-name "web"))
;; In particular, catch 'UnableToResolveError'
(catch :default e
;; (errorf e "Unable to load npm websocket lib")
nil))))))))

#?(:cljs
(defrecord ChWebSocket
Expand Down

0 comments on commit 47c4e7d

Please sign in to comment.