From ac207e276cebe3335c8c9d5443e40642183e3ead Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Fri, 6 Oct 2023 12:18:01 +0200 Subject: [PATCH] :zap: Restore performance optimization of direct prop access Using safer optional chain operator --- common/src/app/common/data/macros.cljc | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/common/src/app/common/data/macros.cljc b/common/src/app/common/data/macros.cljc index 697dcc20e..3d3c1d1b1 100644 --- a/common/src/app/common/data/macros.cljc +++ b/common/src/app/common/data/macros.cljc @@ -13,8 +13,8 @@ #?(:clj [clojure.core :as c] :cljs [cljs.core :as c]) [app.common.data :as d] - [cuerdas.core :as str] - [cljs.analyzer.api :as aapi])) + [cljs.analyzer.api :as aapi] + [cuerdas.core :as str])) (defmacro select-keys "A macro version of `select-keys`. Useful when keys vector is known @@ -120,12 +120,9 @@ "A macro based, optimized variant of `get` that access the property directly on CLJS, on CLJ works as get." [obj prop] - ;; This throws an exception if obj is nul, that does not occur with CLJ get. - ;; This is causing many internal errors in places that obj null does not harm and should not throw. - ;; (if (:ns &env) - ;; (list (symbol ".") (with-meta obj {:tag 'js}) (symbol (str "-" (c/name prop)))) - (list `c/get obj prop)) - ;;) + (if (:ns &env) + (list 'js* (c/str "(~{}?." (str/snake prop) ")") obj) + (list `c/get obj prop))) (def ^:dynamic *assert-context* nil)