This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-10-06
Channels
- # aleph (79)
- # bangalore-clj (3)
- # beginners (49)
- # boot (74)
- # cider (10)
- # cljs-dev (21)
- # cljsrn (2)
- # clojure (105)
- # clojure-berlin (1)
- # clojure-brasil (1)
- # clojure-dusseldorf (1)
- # clojure-korea (1)
- # clojure-poland (3)
- # clojure-russia (38)
- # clojure-spec (146)
- # clojure-uk (20)
- # clojurescript (70)
- # cloverage (1)
- # component (1)
- # core-async (23)
- # css (16)
- # cursive (22)
- # datascript (1)
- # datomic (22)
- # defnpodcast (6)
- # emacs (60)
- # events (1)
- # hoplon (94)
- # jobs (1)
- # jobs-rus (13)
- # luminus (11)
- # off-topic (11)
- # om (48)
- # onyx (5)
- # proton (7)
- # re-frame (87)
- # reagent (39)
- # rethinkdb (1)
- # ring-swagger (14)
- # rum (6)
- # specter (14)
- # untangled (105)
- # vim (6)
- # yada (22)
hello, I’m using Om
and I’m trying to change the h1 label
when I press a button. I don’t know what is wrong in the following code. Could anyone help me?
(defn setText
[owner label word]
(let [field (om/get-node owner label)]
(set! (.-text field) (language/translate word))))
(om/root
(fn [data owner]
(om/component
(dom/div nil
(dom/h1 #js {:ref "text"} (language/translate "welcome"))
(dom/div nil
(dom/button
#js {
:onClick #((language/set-language "en") (setText owner "text" "welcome"))}
"English")
(dom/div nil
(dom/button
#js {
:onClick #((language/set-language "es") (setText owner "text" "welcome"))}
"Spanish"))))))
app-state
{:target (. js/document (getElementById "content"))})
@rackdon hello. You shouldn't set the text property directly, but instead update the app state and allow om to call your render fn which should get the value from the component props. It also looks like you are missing a do
on your onclick fns, but that is irrelevant to your issue.
Om.next is nearly in beta, so you might consider learning that instead if possible. 🙂
the problem is that this data are not in the app state because I read one of the values from the local storage, and then I reevaluate the string that I’m going to show
must I introduce all the data in the app state, reevaluate all the values, change them in the app state and then update the view?
I’ll give you the context, maybe it’s easier….. I have a button than change the languaje. I have all the translations inside a file.
def dictionaries {
:es {
:welcome “Bienvenido"
}
:en {
:welcome “Welcome”
}
}
If I click a button, local storage variable change the value to “es” and then I want to render all the words as spanish, and the same por english
@rackdon yes, the recommend approach is to put all the data needed for your view at the app-state, you can do that on the app startup and then just keep it in sync on your transactions (to cause a change, trigger a transaction, inside of there you can update both app state and local storage if you must)
ah, I just noticed you are using the om now, well, most still applies, but like @cmcfarlen said, if you can, try to learn the om.next
@anmonteiro do you have a demo / boot/ lein template of a compassus application with server side rendering kicking around by any chance?
just the bare bones would be amazing - something like your oriens
template but with a rudimentary server too
@danieleneal unfortunately no, I haven’t. the plan is to include it in oriens
as an option
Compassus has been designed with server-side rendering in mind, though
oh cool, that would be great if it goes in oriens
as an option
so it should be quite easy to integrate
that’s great to hear
@danieleneal a contribution to Oriens is very welcome if you end up putting something together
I don’t have time to work on that for the moment
I’m guessing the best starting point is the om-next-full-stack
demo you have up?
yeah, hooking it up shouldn’t be too hard, happy to answer any questions along the way
om-next-fullstack
is probably a good starting point
@danieleneal BTW the Compassus tests run in Clojure too so that might be worth looking into as well
ah do you have a time to answer a question about the om-next-full-stack
demo?
go ahead
I’ve noticed that the clearing a task appears not to do anything on the client - although if I refresh the page after deleting, then the tasks are gone
so a request is definitely being made
sorry I don’t understand what your question is
I don’t know if this is a bug
right, it’s not implemented at all
or if it’s just doing server side
I copied the code over from David’s om-next-demo
, which doesn’t implement that
and the client side bit is not done
ah ok
I also think you can’t add tasks
there are a few bits which just aren’t implemented
but I really don’t care because that’s not the point of the example 🙂
ah, ok so I should just look at the toggle of todos on and off, and use that
yeah - I just wanted to check that the whole end to end thing was there
thank you
totally doesn’t matter if some functionality is missing
React VR has been announced https://twitter.com/reactjs/status/784088700460204032