Reagent/ClojureScript - multiple component aspect updates
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I have a select component which shows a label and the associated options. There is a separate 'language' select which should choose the language of the display. On change it updates both @language which choses the label language and @search-language-options which provides the options to the select.
The label updates as expected, but the options list does not - it remains as originally initialised.
;; search-languages -> vector
;; return the languages referenced in the data for options use
(defn search-languages
(let [options (list (tr {:dict ld} [@language :en] [:choice-any]))]
(if (= @language :or) (concat options (vec (set (map (partial get-field "lang") parsed-json))))
(concat options (vec (set (map (partial get-field "langTranslated") parsed-json)))))))
(def search-language-options (r/atom (search-languages)))
;; filter component -> component
;; create a select
(defn select-filter-component [label value options]
[:div {:class "form-group"}
[:label {:class "control-label" :for label} label]
[:select {:id label :class "form-control" :value @value :on-change #(reset! value (-> % .-target .-value))}
(for [opt options]
^{:key opt} [:option {:value opt} opt])]])
;; lang-select -> component
;; choose display language
(defn lang-select
[:div {:class "form-control" }
[:select {:id :en :value @language :on-change (fn [e]
(reset! language (.. e -target -value))
(reset! search-language-options (search-languages)))
}
^{:key :en} [:option {:value :en} "English"]
^{:key :fr} [:option {:value :fr} "Français"]
^{:key :es} [:option {:value :es} "Español"]
^{:key :or} [:option {:value :or} "Original language"]
]])
;; filter form
;; filter the results
(defn filter-form
[:form {:class "form-inline"}
[search-filter-component (tr {:dict ld} [@language :en] [:search] ) search-text]
[select-filter-component (tr {:dict ld} [@language :en] [:language] ) search-language @search-language-options]
[select-filter-component (tr {:dict ld} [@language :en] [:gender] ) gender ["Any" "M" "F"]]
[select-filter-component (tr {:dict ld} [@language :en] [:continent/title] ) continent ["Any" "Europe"]]
[select-filter-component (tr {:dict ld} [@language :en] [:country] ) placeTranslated ["Any" "Austria" "Switzerland" "Germany"]]
[select-filter-component (tr {:dict ld} [@language :en] [:literaryForm] ) literaryForm ["Any" "Drama" "Poetry" "Prose: fiction" "Prose: non-fiction" ]]
[select-filter-component (tr {:dict ld} [@language :en] [:genre] ) genre ["Any" "Short story" "Novella" "Graphic Novel"]]
[reset-button]]
)
clojurescript reagent
add a comment |
I have a select component which shows a label and the associated options. There is a separate 'language' select which should choose the language of the display. On change it updates both @language which choses the label language and @search-language-options which provides the options to the select.
The label updates as expected, but the options list does not - it remains as originally initialised.
;; search-languages -> vector
;; return the languages referenced in the data for options use
(defn search-languages
(let [options (list (tr {:dict ld} [@language :en] [:choice-any]))]
(if (= @language :or) (concat options (vec (set (map (partial get-field "lang") parsed-json))))
(concat options (vec (set (map (partial get-field "langTranslated") parsed-json)))))))
(def search-language-options (r/atom (search-languages)))
;; filter component -> component
;; create a select
(defn select-filter-component [label value options]
[:div {:class "form-group"}
[:label {:class "control-label" :for label} label]
[:select {:id label :class "form-control" :value @value :on-change #(reset! value (-> % .-target .-value))}
(for [opt options]
^{:key opt} [:option {:value opt} opt])]])
;; lang-select -> component
;; choose display language
(defn lang-select
[:div {:class "form-control" }
[:select {:id :en :value @language :on-change (fn [e]
(reset! language (.. e -target -value))
(reset! search-language-options (search-languages)))
}
^{:key :en} [:option {:value :en} "English"]
^{:key :fr} [:option {:value :fr} "Français"]
^{:key :es} [:option {:value :es} "Español"]
^{:key :or} [:option {:value :or} "Original language"]
]])
;; filter form
;; filter the results
(defn filter-form
[:form {:class "form-inline"}
[search-filter-component (tr {:dict ld} [@language :en] [:search] ) search-text]
[select-filter-component (tr {:dict ld} [@language :en] [:language] ) search-language @search-language-options]
[select-filter-component (tr {:dict ld} [@language :en] [:gender] ) gender ["Any" "M" "F"]]
[select-filter-component (tr {:dict ld} [@language :en] [:continent/title] ) continent ["Any" "Europe"]]
[select-filter-component (tr {:dict ld} [@language :en] [:country] ) placeTranslated ["Any" "Austria" "Switzerland" "Germany"]]
[select-filter-component (tr {:dict ld} [@language :en] [:literaryForm] ) literaryForm ["Any" "Drama" "Poetry" "Prose: fiction" "Prose: non-fiction" ]]
[select-filter-component (tr {:dict ld} [@language :en] [:genre] ) genre ["Any" "Short story" "Novella" "Graphic Novel"]]
[reset-button]]
)
clojurescript reagent
add a comment |
I have a select component which shows a label and the associated options. There is a separate 'language' select which should choose the language of the display. On change it updates both @language which choses the label language and @search-language-options which provides the options to the select.
The label updates as expected, but the options list does not - it remains as originally initialised.
;; search-languages -> vector
;; return the languages referenced in the data for options use
(defn search-languages
(let [options (list (tr {:dict ld} [@language :en] [:choice-any]))]
(if (= @language :or) (concat options (vec (set (map (partial get-field "lang") parsed-json))))
(concat options (vec (set (map (partial get-field "langTranslated") parsed-json)))))))
(def search-language-options (r/atom (search-languages)))
;; filter component -> component
;; create a select
(defn select-filter-component [label value options]
[:div {:class "form-group"}
[:label {:class "control-label" :for label} label]
[:select {:id label :class "form-control" :value @value :on-change #(reset! value (-> % .-target .-value))}
(for [opt options]
^{:key opt} [:option {:value opt} opt])]])
;; lang-select -> component
;; choose display language
(defn lang-select
[:div {:class "form-control" }
[:select {:id :en :value @language :on-change (fn [e]
(reset! language (.. e -target -value))
(reset! search-language-options (search-languages)))
}
^{:key :en} [:option {:value :en} "English"]
^{:key :fr} [:option {:value :fr} "Français"]
^{:key :es} [:option {:value :es} "Español"]
^{:key :or} [:option {:value :or} "Original language"]
]])
;; filter form
;; filter the results
(defn filter-form
[:form {:class "form-inline"}
[search-filter-component (tr {:dict ld} [@language :en] [:search] ) search-text]
[select-filter-component (tr {:dict ld} [@language :en] [:language] ) search-language @search-language-options]
[select-filter-component (tr {:dict ld} [@language :en] [:gender] ) gender ["Any" "M" "F"]]
[select-filter-component (tr {:dict ld} [@language :en] [:continent/title] ) continent ["Any" "Europe"]]
[select-filter-component (tr {:dict ld} [@language :en] [:country] ) placeTranslated ["Any" "Austria" "Switzerland" "Germany"]]
[select-filter-component (tr {:dict ld} [@language :en] [:literaryForm] ) literaryForm ["Any" "Drama" "Poetry" "Prose: fiction" "Prose: non-fiction" ]]
[select-filter-component (tr {:dict ld} [@language :en] [:genre] ) genre ["Any" "Short story" "Novella" "Graphic Novel"]]
[reset-button]]
)
clojurescript reagent
I have a select component which shows a label and the associated options. There is a separate 'language' select which should choose the language of the display. On change it updates both @language which choses the label language and @search-language-options which provides the options to the select.
The label updates as expected, but the options list does not - it remains as originally initialised.
;; search-languages -> vector
;; return the languages referenced in the data for options use
(defn search-languages
(let [options (list (tr {:dict ld} [@language :en] [:choice-any]))]
(if (= @language :or) (concat options (vec (set (map (partial get-field "lang") parsed-json))))
(concat options (vec (set (map (partial get-field "langTranslated") parsed-json)))))))
(def search-language-options (r/atom (search-languages)))
;; filter component -> component
;; create a select
(defn select-filter-component [label value options]
[:div {:class "form-group"}
[:label {:class "control-label" :for label} label]
[:select {:id label :class "form-control" :value @value :on-change #(reset! value (-> % .-target .-value))}
(for [opt options]
^{:key opt} [:option {:value opt} opt])]])
;; lang-select -> component
;; choose display language
(defn lang-select
[:div {:class "form-control" }
[:select {:id :en :value @language :on-change (fn [e]
(reset! language (.. e -target -value))
(reset! search-language-options (search-languages)))
}
^{:key :en} [:option {:value :en} "English"]
^{:key :fr} [:option {:value :fr} "Français"]
^{:key :es} [:option {:value :es} "Español"]
^{:key :or} [:option {:value :or} "Original language"]
]])
;; filter form
;; filter the results
(defn filter-form
[:form {:class "form-inline"}
[search-filter-component (tr {:dict ld} [@language :en] [:search] ) search-text]
[select-filter-component (tr {:dict ld} [@language :en] [:language] ) search-language @search-language-options]
[select-filter-component (tr {:dict ld} [@language :en] [:gender] ) gender ["Any" "M" "F"]]
[select-filter-component (tr {:dict ld} [@language :en] [:continent/title] ) continent ["Any" "Europe"]]
[select-filter-component (tr {:dict ld} [@language :en] [:country] ) placeTranslated ["Any" "Austria" "Switzerland" "Germany"]]
[select-filter-component (tr {:dict ld} [@language :en] [:literaryForm] ) literaryForm ["Any" "Drama" "Poetry" "Prose: fiction" "Prose: non-fiction" ]]
[select-filter-component (tr {:dict ld} [@language :en] [:genre] ) genre ["Any" "Short story" "Novella" "Graphic Novel"]]
[reset-button]]
)
clojurescript reagent
clojurescript reagent
edited Nov 20 '18 at 10:10
Steve
asked Nov 16 '18 at 15:35
SteveSteve
63
63
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Do you mean that the [:option...] elements in select-filter-component don't change? If that's what you mean, it is hard to tell from the code posted why they don't change because those options are rendered based on the props passed into select-filter-component, and you haven't shown how you are calling select-filter-component. Specifically this code is completely dependent on the options prop passed in:
(for [opt options]
^{:key opt} [:option {:value opt} opt])
(Side note: though it doesn't matter here, note that for is lazy, so if you ever reference an atom in a for note that you'll have to wrap it in a doall or the atom won't be referenced during rendering and your component won't update when the atom updates.)
If you mean that selecting different options with the mouse doesn't work, then that is because you have commented out the on-change handler.
The [:option...] elements in select-filter-component don't change. I added in theselect-filter-componentcalling code to the snippets. Ignore the `(tr ...) this just does i18n stuff.
– Steve
Nov 20 '18 at 10:17
Generally, swapping out the options seems to work on a small example in my repo. Try some log statements in each component to see if they are rerendering with the data you expect. (Note, when you swap out the options, you are swapping not only the display name but also the value. The value atom will have to be swapped to or the selected value will be invalid and you'll lose the selection state.)
– Justin L.
Nov 23 '18 at 18:38
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53340973%2freagent-clojurescript-multiple-component-aspect-updates%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Do you mean that the [:option...] elements in select-filter-component don't change? If that's what you mean, it is hard to tell from the code posted why they don't change because those options are rendered based on the props passed into select-filter-component, and you haven't shown how you are calling select-filter-component. Specifically this code is completely dependent on the options prop passed in:
(for [opt options]
^{:key opt} [:option {:value opt} opt])
(Side note: though it doesn't matter here, note that for is lazy, so if you ever reference an atom in a for note that you'll have to wrap it in a doall or the atom won't be referenced during rendering and your component won't update when the atom updates.)
If you mean that selecting different options with the mouse doesn't work, then that is because you have commented out the on-change handler.
The [:option...] elements in select-filter-component don't change. I added in theselect-filter-componentcalling code to the snippets. Ignore the `(tr ...) this just does i18n stuff.
– Steve
Nov 20 '18 at 10:17
Generally, swapping out the options seems to work on a small example in my repo. Try some log statements in each component to see if they are rerendering with the data you expect. (Note, when you swap out the options, you are swapping not only the display name but also the value. The value atom will have to be swapped to or the selected value will be invalid and you'll lose the selection state.)
– Justin L.
Nov 23 '18 at 18:38
add a comment |
Do you mean that the [:option...] elements in select-filter-component don't change? If that's what you mean, it is hard to tell from the code posted why they don't change because those options are rendered based on the props passed into select-filter-component, and you haven't shown how you are calling select-filter-component. Specifically this code is completely dependent on the options prop passed in:
(for [opt options]
^{:key opt} [:option {:value opt} opt])
(Side note: though it doesn't matter here, note that for is lazy, so if you ever reference an atom in a for note that you'll have to wrap it in a doall or the atom won't be referenced during rendering and your component won't update when the atom updates.)
If you mean that selecting different options with the mouse doesn't work, then that is because you have commented out the on-change handler.
The [:option...] elements in select-filter-component don't change. I added in theselect-filter-componentcalling code to the snippets. Ignore the `(tr ...) this just does i18n stuff.
– Steve
Nov 20 '18 at 10:17
Generally, swapping out the options seems to work on a small example in my repo. Try some log statements in each component to see if they are rerendering with the data you expect. (Note, when you swap out the options, you are swapping not only the display name but also the value. The value atom will have to be swapped to or the selected value will be invalid and you'll lose the selection state.)
– Justin L.
Nov 23 '18 at 18:38
add a comment |
Do you mean that the [:option...] elements in select-filter-component don't change? If that's what you mean, it is hard to tell from the code posted why they don't change because those options are rendered based on the props passed into select-filter-component, and you haven't shown how you are calling select-filter-component. Specifically this code is completely dependent on the options prop passed in:
(for [opt options]
^{:key opt} [:option {:value opt} opt])
(Side note: though it doesn't matter here, note that for is lazy, so if you ever reference an atom in a for note that you'll have to wrap it in a doall or the atom won't be referenced during rendering and your component won't update when the atom updates.)
If you mean that selecting different options with the mouse doesn't work, then that is because you have commented out the on-change handler.
Do you mean that the [:option...] elements in select-filter-component don't change? If that's what you mean, it is hard to tell from the code posted why they don't change because those options are rendered based on the props passed into select-filter-component, and you haven't shown how you are calling select-filter-component. Specifically this code is completely dependent on the options prop passed in:
(for [opt options]
^{:key opt} [:option {:value opt} opt])
(Side note: though it doesn't matter here, note that for is lazy, so if you ever reference an atom in a for note that you'll have to wrap it in a doall or the atom won't be referenced during rendering and your component won't update when the atom updates.)
If you mean that selecting different options with the mouse doesn't work, then that is because you have commented out the on-change handler.
answered Nov 17 '18 at 23:38
Justin L.Justin L.
18218
18218
The [:option...] elements in select-filter-component don't change. I added in theselect-filter-componentcalling code to the snippets. Ignore the `(tr ...) this just does i18n stuff.
– Steve
Nov 20 '18 at 10:17
Generally, swapping out the options seems to work on a small example in my repo. Try some log statements in each component to see if they are rerendering with the data you expect. (Note, when you swap out the options, you are swapping not only the display name but also the value. The value atom will have to be swapped to or the selected value will be invalid and you'll lose the selection state.)
– Justin L.
Nov 23 '18 at 18:38
add a comment |
The [:option...] elements in select-filter-component don't change. I added in theselect-filter-componentcalling code to the snippets. Ignore the `(tr ...) this just does i18n stuff.
– Steve
Nov 20 '18 at 10:17
Generally, swapping out the options seems to work on a small example in my repo. Try some log statements in each component to see if they are rerendering with the data you expect. (Note, when you swap out the options, you are swapping not only the display name but also the value. The value atom will have to be swapped to or the selected value will be invalid and you'll lose the selection state.)
– Justin L.
Nov 23 '18 at 18:38
The [:option...] elements in select-filter-component don't change. I added in the
select-filter-component calling code to the snippets. Ignore the `(tr ...) this just does i18n stuff.– Steve
Nov 20 '18 at 10:17
The [:option...] elements in select-filter-component don't change. I added in the
select-filter-component calling code to the snippets. Ignore the `(tr ...) this just does i18n stuff.– Steve
Nov 20 '18 at 10:17
Generally, swapping out the options seems to work on a small example in my repo. Try some log statements in each component to see if they are rerendering with the data you expect. (Note, when you swap out the options, you are swapping not only the display name but also the value. The value atom will have to be swapped to or the selected value will be invalid and you'll lose the selection state.)
– Justin L.
Nov 23 '18 at 18:38
Generally, swapping out the options seems to work on a small example in my repo. Try some log statements in each component to see if they are rerendering with the data you expect. (Note, when you swap out the options, you are swapping not only the display name but also the value. The value atom will have to be swapped to or the selected value will be invalid and you'll lose the selection state.)
– Justin L.
Nov 23 '18 at 18:38
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53340973%2freagent-clojurescript-multiple-component-aspect-updates%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown