-
-
Save claudiuapetrei/77043c6c18e6861681be59109c4a7b6b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;defsc = Macro that generates the code for a react-js component | |
;##### | |
;Compile time checking on literals | |
;##### | |
;Works | |
(defsc Person [this {:keys [person/name person/age]}] | |
{:query [:person/name :person/age] | |
:initial-state (fn [{:keys [name age] :as params}] {:person/name name :person/age age})} | |
(dom/li | |
(dom/h5 (str name "(age: " age ")")))) | |
;Destructuring something-else. I get compile time error. | |
(defsc Person [this {:keys [person/name person/age person/something-else]}] ; <---here | |
{:query [:person/name :person/age] | |
:initial-state (fn [{:keys [name age] :as params}] {:person/name name :person/age age})} | |
(dom/li | |
(dom/h5 (str name "(age: " age ")")))) | |
[:main] Build failure: | |
------ ERROR ------------------------------------------------------------------- | |
File: /home/claudiu/clojure/clojurestacks/src/main/app/clojurestacks/ui/root.cljc:34:19 | |
-------------------------------------------------------------------------------- | |
31 | | |
32 | | |
33 | (defsc Person [this {:keys [person/name person/age person/something-else]}] | |
34 | {:query [:person/name :person/age] | |
-------------------------^------------------------------------------------------ | |
defsc Person: [person/something-else] was destructured in props, but does not appear in the :query! at line 34 clojurestacks/ui/root.cljc | |
-------------------------------------------------------------------------------- | |
35 | :initial-state (fn [{:keys [name age] :as params}] {:person/name name :person/age age})} | |
36 | (dom/li | |
37 | (dom/h5 (str name "(age: " age ")")))) | |
38 | | |
-------------------------------------------------------------------------------- | |
;Fix - for the build to work | |
(defsc Person [this {:keys [person/name person/age person/something-else]}] | |
{:query [:person/name :person/age :person/something-else] ; <--- fix here | |
:initial-state (fn [{:keys [name age] :as params}] {:person/name name :person/age age})} | |
(dom/li | |
(dom/h5 (str name "(age: " age ")")))) | |
; ####################### | |
; What it writes | |
; ####################### | |
user=> (clojure.pprint/pprint (macroexpand '(defsc Person [this {:keys [person/name person/age]}] | |
#_=> {:query [:person/name :person/age] | |
#_=> :initial-state (fn [{:keys [name age] :as params}] {:person/name name :person/age age})} | |
#_=> (dom/li | |
#_=> (dom/h5 (str name "(age: " age ")")))))) | |
(do | |
nil | |
(clojure.core/declare Person) | |
(clojure.core/defrecord | |
Person_klass | |
[state refs props children] | |
fulcro.client.impl.protocols/IReactLifecycle | |
(componentWillMount | |
[this__15366__auto__] | |
(clojure.core/let | |
[reconciler__15367__auto__ | |
(fulcro.client.primitives/get-reconciler this__15366__auto__) | |
lifecycle__15368__auto__ | |
(clojure.core/get-in | |
reconciler__15367__auto__ | |
[:config :lifecycle]) | |
indexer__15369__auto__ | |
(clojure.core/get-in | |
reconciler__15367__auto__ | |
[:config :indexer])] | |
(clojure.core/when-not | |
(clojure.core/nil? lifecycle__15368__auto__) | |
(lifecycle__15368__auto__ this__15366__auto__ :mount)) | |
(clojure.core/when-not | |
(clojure.core/nil? indexer__15369__auto__) | |
(fulcro.client.impl.protocols/index-component! | |
indexer__15369__auto__ | |
this__15366__auto__)))) | |
(initLocalState [this__15366__auto__]) | |
(render | |
[this__15360__auto__] | |
(clojure.core/let | |
[this this__15360__auto__] | |
(clojure.core/binding | |
[fulcro.client.primitives/*reconciler* | |
(fulcro.client.primitives/get-reconciler this__15360__auto__) | |
fulcro.client.primitives/*depth* | |
(clojure.core/inc | |
(fulcro.client.primitives/depth this__15360__auto__)) | |
fulcro.client.primitives/*shared* | |
(fulcro.client.primitives/shared this__15360__auto__) | |
fulcro.client.primitives/*instrument* | |
(fulcro.client.primitives/instrument this__15360__auto__) | |
fulcro.client.primitives/*parent* | |
this__15360__auto__] | |
(clojure.core/let | |
[ret__15361__auto__ | |
(do | |
(clojure.core/let | |
[{:keys [person/name person/age]} | |
(fulcro.client.primitives/props this)] | |
(dom/li (dom/h5 (str name "(age: " age ")"))))) | |
props__15362__auto__ | |
(:props this__15360__auto__)] | |
(clojure.core/when-not | |
@(:fulcro$mounted? props__15362__auto__) | |
(clojure.core/swap! | |
(:fulcro$mounted? props__15362__auto__) | |
clojure.core/not)) | |
ret__15361__auto__)))) | |
fulcro.client.primitives/InitialAppState | |
(initial-state | |
[this {:keys [name age], :as params}] | |
#:person{:name name, :age age}) | |
fulcro.client.primitives/IQuery | |
(query [this] [:person/name :person/age]) | |
fulcro.client.impl.protocols/IReactComponent | |
(-render | |
[this__15548__auto__] | |
(fulcro.client.impl.protocols/componentWillMount | |
this__15548__auto__) | |
(fulcro.client.impl.protocols/render this__15548__auto__))) | |
(clojure.core/defmethod | |
clojure.core/print-method | |
user.Person_klass | |
[o__15549__auto__ w__15550__auto__] | |
(.write | |
w__15550__auto__ | |
(clojure.core/str | |
"#object[" | |
(clojure.core/ns-name clojure.core/*ns*) | |
"/" | |
"Person" | |
"]"))) | |
(clojure.core/let | |
[c__15551__auto__ | |
(clojure.core/fn | |
Person | |
[state__15552__auto__ | |
refs__15553__auto__ | |
props__15554__auto__ | |
children__15555__auto__] | |
(user.Person_klass. | |
state__15552__auto__ | |
refs__15553__auto__ | |
props__15554__auto__ | |
children__15555__auto__))] | |
(def | |
Person | |
(clojure.core/with-meta | |
c__15551__auto__ | |
(clojure.core/merge | |
{:component-name "Person", | |
:component c__15551__auto__, | |
:component-ns (clojure.core/ns-name clojure.core/*ns*)} | |
{:initial-state | |
(fn | |
([this {:keys [name age], :as params}] | |
#:person{:name name, :age age})), | |
:query (fn ([this] [:person/name :person/age])), | |
:params (fn [this])}))))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment