From 251fccf7b6d3e00f7a5dc93ea70bbc76dc5433f1 Mon Sep 17 00:00:00 2001 From: Nazarii Fenii Date: Tue, 6 Feb 2024 13:45:34 +0200 Subject: [PATCH 1/9] Added destructuring section to new guidelines --- doc/new-guidelines.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/doc/new-guidelines.md b/doc/new-guidelines.md index 793d72ec60f..9b20b4ffb24 100644 --- a/doc/new-guidelines.md +++ b/doc/new-guidelines.md @@ -74,6 +74,32 @@ This mistake mostly happens with functional components. It's important to name functional components with `f-` prefix. +### Default value when destructuring + +Too often callers pass nil values because values can be wrapped in a `when` for example. +In this case, the default value is not applied, because :or macro will use default only when the value is absent. +Instead, use `(or value some-default-value)` in a `let` expression or as a parameter value. + +```clojure +;; bad (unreliable) +(defn- view-internal + [{:keys [auto-focus + init-value + return-key-type] + :or {auto-focus false + init-value 0 + return-key-type :done}}]) + +;; good +(defn- view-internal + [{:keys [auto-focus + init-value + return-key-type]}]) + (let [auto-focus (or auto-focus? false) + init-value (or init-value 0) + return-key-type (or return-key-type :done)]) +``` + ### Component props and API scheme to match Figma as closely as possible Ideally, the prop names for components (particularly in quo Design System) From 302c22f21410a4d83ed86c5bc2dbfeadeb2ee3ae Mon Sep 17 00:00:00 2001 From: Nazarii Fenii Date: Tue, 6 Feb 2024 14:52:04 +0200 Subject: [PATCH 2/9] Updated auto-focus? param --- doc/new-guidelines.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/new-guidelines.md b/doc/new-guidelines.md index 9b20b4ffb24..160efba4f49 100644 --- a/doc/new-guidelines.md +++ b/doc/new-guidelines.md @@ -83,19 +83,19 @@ Instead, use `(or value some-default-value)` in a `let` expression or as a param ```clojure ;; bad (unreliable) (defn- view-internal - [{:keys [auto-focus + [{:keys [auto-focus? init-value return-key-type] - :or {auto-focus false + :or {auto-focus? false init-value 0 return-key-type :done}}]) ;; good (defn- view-internal - [{:keys [auto-focus + [{:keys [auto-focus? init-value return-key-type]}]) - (let [auto-focus (or auto-focus? false) + (let [auto-focus? (or auto-focus? false) init-value (or init-value 0) return-key-type (or return-key-type :done)]) ``` From 3c93e68cf28799f6708dcb3431504afb0ea504e5 Mon Sep 17 00:00:00 2001 From: Nazarii Fenii Date: Wed, 7 Feb 2024 16:19:01 +0200 Subject: [PATCH 3/9] Moved destructuring section to quo/readme --- doc/new-guidelines.md | 26 -------------------------- src/quo/README.md | 26 ++++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/doc/new-guidelines.md b/doc/new-guidelines.md index 160efba4f49..793d72ec60f 100644 --- a/doc/new-guidelines.md +++ b/doc/new-guidelines.md @@ -74,32 +74,6 @@ This mistake mostly happens with functional components. It's important to name functional components with `f-` prefix. -### Default value when destructuring - -Too often callers pass nil values because values can be wrapped in a `when` for example. -In this case, the default value is not applied, because :or macro will use default only when the value is absent. -Instead, use `(or value some-default-value)` in a `let` expression or as a parameter value. - -```clojure -;; bad (unreliable) -(defn- view-internal - [{:keys [auto-focus? - init-value - return-key-type] - :or {auto-focus? false - init-value 0 - return-key-type :done}}]) - -;; good -(defn- view-internal - [{:keys [auto-focus? - init-value - return-key-type]}]) - (let [auto-focus? (or auto-focus? false) - init-value (or init-value 0) - return-key-type (or return-key-type :done)]) -``` - ### Component props and API scheme to match Figma as closely as possible Ideally, the prop names for components (particularly in quo Design System) diff --git a/src/quo/README.md b/src/quo/README.md index 5ef3e5a7ca5..d15556e65f5 100644 --- a/src/quo/README.md +++ b/src/quo/README.md @@ -106,6 +106,32 @@ The convention is `:size-`, e.g size `20` is `:size-20` - Try to make all other vars private because they should almost never be used directly. +### Default value when destructuring + +Too often callers pass nil values because values can be wrapped in a `when` for example. +In this case, the default value is not applied, because :or macro will use default only when the value is absent. +Instead, use `(or value some-default-value)` in a `let` expression or as a parameter value. + +```clojure +;; bad (unreliable) +(defn- view-internal + [{:keys [auto-focus? + init-value + return-key-type] + :or {auto-focus? false + init-value 0 + return-key-type :done}}]) + +;; good +(defn- view-internal + [{:keys [{default-auto-focus? :auto-focus? + default-init-value :init-value + default-return-key-type :return-key-type}]}]) + (let [auto-focus? (or default-auto-focus? false) + init-value (or default-init-value 0) + return-key-type (or default-return-key-type :done)]) +``` + ## Component tests We don't attempt to write component tests verifying how components look on the From ab757444d22e24aed893788d55e7df6a6e1546b2 Mon Sep 17 00:00:00 2001 From: Nazarii Fenii Date: Wed, 7 Feb 2024 16:21:50 +0200 Subject: [PATCH 4/9] Updated heading --- src/quo/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/quo/README.md b/src/quo/README.md index d15556e65f5..01b9b52d152 100644 --- a/src/quo/README.md +++ b/src/quo/README.md @@ -106,7 +106,7 @@ The convention is `:size-`, e.g size `20` is `:size-20` - Try to make all other vars private because they should almost never be used directly. -### Default value when destructuring +## Default value when destructuring Too often callers pass nil values because values can be wrapped in a `when` for example. In this case, the default value is not applied, because :or macro will use default only when the value is absent. From d397f2d912f09820c822d89ec195d57ebbbc3cb7 Mon Sep 17 00:00:00 2001 From: Nazarii Fenii Date: Wed, 7 Feb 2024 16:22:44 +0200 Subject: [PATCH 5/9] Updated heading --- src/quo/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/quo/README.md b/src/quo/README.md index 01b9b52d152..73a462c532c 100644 --- a/src/quo/README.md +++ b/src/quo/README.md @@ -106,7 +106,7 @@ The convention is `:size-`, e.g size `20` is `:size-20` - Try to make all other vars private because they should almost never be used directly. -## Default value when destructuring +# Default value when destructuring Too often callers pass nil values because values can be wrapped in a `when` for example. In this case, the default value is not applied, because :or macro will use default only when the value is absent. From 3e53c65c97eb31ea8379e55a53565d6f915be32d Mon Sep 17 00:00:00 2001 From: Nazarii Fenii Date: Wed, 7 Feb 2024 16:24:53 +0200 Subject: [PATCH 6/9] Revert: Updated heading --- src/quo/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/quo/README.md b/src/quo/README.md index 73a462c532c..01b9b52d152 100644 --- a/src/quo/README.md +++ b/src/quo/README.md @@ -106,7 +106,7 @@ The convention is `:size-`, e.g size `20` is `:size-20` - Try to make all other vars private because they should almost never be used directly. -# Default value when destructuring +## Default value when destructuring Too often callers pass nil values because values can be wrapped in a `when` for example. In this case, the default value is not applied, because :or macro will use default only when the value is absent. From febd3cbc50648567caa37554f9176d7abebdaa2a Mon Sep 17 00:00:00 2001 From: Nazarii Fenii Date: Thu, 22 Feb 2024 09:59:10 +0200 Subject: [PATCH 7/9] Updated quo destructuring gudelines --- src/quo/README.md | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/quo/README.md b/src/quo/README.md index 01b9b52d152..fccbb14676d 100644 --- a/src/quo/README.md +++ b/src/quo/README.md @@ -124,12 +124,11 @@ Instead, use `(or value some-default-value)` in a `let` expression or as a param ;; good (defn- view-internal - [{:keys [{default-auto-focus? :auto-focus? - default-init-value :init-value - default-return-key-type :return-key-type}]}]) - (let [auto-focus? (or default-auto-focus? false) - init-value (or default-init-value 0) - return-key-type (or default-return-key-type :done)]) + [{:keys [theme size something] :as props}] + (let [auto-focus? (or (:auto-focus? props) false) + init-value (or (:init-value props) 0) + return-key-type (or (:return-key-type props) :done)] + ...)) ``` ## Component tests From 1b53df9acd7d844f4eecc8a01aadecacdcff42ef Mon Sep 17 00:00:00 2001 From: Nazarii Fenii Date: Thu, 22 Feb 2024 09:59:25 +0200 Subject: [PATCH 8/9] Updated quo destructuring gudelines --- src/quo/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/quo/README.md b/src/quo/README.md index fccbb14676d..7ca02b2dff4 100644 --- a/src/quo/README.md +++ b/src/quo/README.md @@ -120,7 +120,8 @@ Instead, use `(or value some-default-value)` in a `let` expression or as a param return-key-type] :or {auto-focus? false init-value 0 - return-key-type :done}}]) + return-key-type :done}}] + ...) ;; good (defn- view-internal From 67e8dcfbf32df7cf0f2035c7e6bba6e459f63b31 Mon Sep 17 00:00:00 2001 From: Nazarii Fenii Date: Thu, 22 Feb 2024 10:10:54 +0200 Subject: [PATCH 9/9] Updated quo destructuring gudelines --- src/quo/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/quo/README.md b/src/quo/README.md index 7ca02b2dff4..34509673666 100644 --- a/src/quo/README.md +++ b/src/quo/README.md @@ -110,7 +110,7 @@ The convention is `:size-`, e.g size `20` is `:size-20` Too often callers pass nil values because values can be wrapped in a `when` for example. In this case, the default value is not applied, because :or macro will use default only when the value is absent. -Instead, use `(or value some-default-value)` in a `let` expression or as a parameter value. +Instead, use `(or (:value props) some-default-value)` in a `let` expression or as a parameter value. ```clojure ;; bad (unreliable)