-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: implement global decorator config #30
base: main
Are you sure you want to change the base?
feat: implement global decorator config #30
Conversation
I agree that accessing the (require '[portfolio.reagent :as pr])
(pr/set-decorator! reagent-decorator) This will just be a convention followed in each adapter, and can be implemented like so: (ns portfolio.reagent
,,,)
(def *decorator* nil)
(defn set-decorator! [decorator]
(set! *decorator* decorator)) Then: ;; Replace this
(let [decorator (or (:reagent (:decorators @app)) identity)] ,,,)
;; ...with
(let [decorator (or *decorator* identity)] ,,,) A note on code-style: I see a lot of the namespace forms have been reformatted in various ways. This makes it hard to gauge what changes you've made. Some of them are reasonable enough, but I'd prefer the PR to only have the minimal changes necessary to support your feature, or at the very least separate commits for stuff like formatting. I also prefer using |
Thank you for the comments. I understand the points. I will change the PR as you said. (just |
Thank you for your patience, I would like to let you know that PR is ready to review. |
Just a friendly reminder. @cjohansen |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the very delayed response!
I like this API a lot better. It still needs to be defined for the remaining non-React adapters, but I can do that. They will probably just be function wrappers.
As I mentioned in the initial comment, there is a lot of unrelated and unnecessary changes to the code, mainly formatting and ordering. I would appreciate if you could revert these, I've highlighted the individual places where I want to keep the original formatting.
[portfolio.react-18 :refer-macros [defscene]] | ||
["react" :as react])) | ||
[portfolio.theme :as theme] | ||
[portfolio.react-18 :refer-macros [defscene]])) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please undo these unrelated changes.
(render [this] | ||
(when (.. this -props -error) | ||
(throw (js/Error. "BOOOOOM!"))) | ||
"Oh, nice!!")) | ||
ctor)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code seems to have been reformatted with no real changes. Please undo it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one still needs fixing
@@ -4,7 +4,8 @@ | |||
;; For react versions 18+ use the following: | |||
;; This is due to the new API https://www.metosin.fi/blog/reagent-towards-react-18/ | |||
(:require [portfolio.components.reagent.component :as rc] | |||
[portfolio.reagent-18 :refer-macros [defscene]])) | |||
[portfolio.theme :as theme] | |||
[portfolio.reagent :refer-macros [defscene]])) | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you change the React version in use here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's maybe lsp related mistake. i will revert it.
[portfolio.theme :as theme] | ||
[portfolio.react-18 :refer-macros [defscene]] | ||
[rum.core :as rum] ;; If you are using an older version of react use the following: | ||
)) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to have been reformatted with no real changes? Please undo it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i will undo it
(:require [portfolio.theme :as theme] | ||
[portfolio.react-18 :refer-macros [defscene]] | ||
[uix.core :refer [$ defui use-state]] | ||
[uix.dom])) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to have been reformatted with no real changes. Please undo it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will undo it
[portfolio.adapter :as adapter])) | ||
[portfolio.adapter :as adapter] | ||
[portfolio.ui.actions :as actions])) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please keep the previous formatting/ordering of this form.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay!
(let [ctor (fn [])] | ||
(let [ctor (fn []) | ||
Decorator (or *decorator* | ||
(.-Fragment react))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I'm reading this right, this will end up defaulting to a fragment instead of a div as before? Seems like an improvement in itself 😊
src/portfolio/react_utils.cljs
Outdated
react "div" #js {} | ||
(if (o/getValueByKeys this "state" "error") | ||
"" | ||
(:component (get-scene this))))))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer if you stuck to the existing formatting here.
src/portfolio/reagent.cljs
Outdated
(if el | ||
(do | ||
(rd/render [decorator | ||
(if (fn? component) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This let introduced a lot of diff noise, and decorator
is only used once. I suggest inlining (or *decorator* identity)
here:
(rd/render [(or *decorator* identity)
(if ,,, ))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay!
src/portfolio/reagent_18.cljs
Outdated
(:require [portfolio.adapter :as adapter] | ||
[portfolio.data :as data] | ||
[reagent.dom.client :as rdc] | ||
[reagent.impl.template :as reagent]) | ||
(:require-macros [portfolio.reagent-18])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please keep the original ordering here.
aa14dd2
to
e427b55
Compare
e427b55
to
d3dc27f
Compare
it's done! please review @cjohansen :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, there are still some pending changes from the previous review. Fix 'em and I'll merge it 😊
(render [this] | ||
(when (.. this -props -error) | ||
(throw (js/Error. "BOOOOOM!"))) | ||
"Oh, nice!!")) | ||
ctor)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one still needs fixing
($ :p "Count: " count) | ||
($ :button {:on-click #(set-count inc)} "Increase")))) | ||
($ :p "Count: " count) | ||
($ :button {:on-click #(set-count inc)} "Increase")))) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one still needs fixing
sample/src/portfolio/scenes.cljs
Outdated
@@ -40,7 +48,7 @@ | |||
|
|||
:viewport/defaults {:viewport/padding [16] | |||
#_#_#_#_:viewport/width 390 | |||
:viewport/height 400} | |||
:viewport/height 400} | |||
#_#_:canvas/layout {:kind :cols |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one still needs fixing
src/portfolio/react_utils.cljs
Outdated
(when-let [actions (:report-render-error (:actions (get-scene this)))] | ||
(actions/dispatch actions nil {:action/exception error | ||
:action/info (js->clj info) | ||
:action/cause "React error boundary caught error"}))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is all reformatting I think? Please keep the original formatting
src/portfolio/react_utils.cljs
Outdated
react "div" #js {} | ||
(if (o/getValueByKeys this "state" "error") | ||
"" | ||
(:component (get-scene this))))))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please maintain the existing formatting here, that will make it easier to see what's actually changing.
all done! (I checked my PR diff one by one) @cjohansen please review |
issue #28
I implemented global decorator support for portfolio.
here is current config api (can be changed)
example decorator implementation.
here is consumer example scene.
Issue
I just read decorators config from
@app
atom. I know it's not ideal, but it's difficult for me to understand the whole structure. Can you give me a suggestion please?TODO