Fork me on GitHub
#om
<
2016-10-06
>
rackdon10:10:54

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"))})

cmcfarlen13:10:03

@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.

cmcfarlen13:10:40

Om.next is nearly in beta, so you might consider learning that instead if possible. 🙂

rackdon13:10:51

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

rackdon13:10:29

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?

rackdon13:10:45

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”
   } 
}

rackdon13:10:32

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

wilkerlucio13:10:33

@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)

wilkerlucio13:10:42

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

rackdon13:10:37

Ok I’ll do that approach. Tanks both a lot!!!!

danielneal15:10:44

@anmonteiro do you have a demo / boot/ lein template of a compassus application with server side rendering kicking around by any chance?

danielneal15:10:30

just the bare bones would be amazing - something like your oriens template but with a rudimentary server too

anmonteiro15:10:19

@danieleneal unfortunately no, I haven’t. the plan is to include it in oriens as an option

anmonteiro15:10:39

Compassus has been designed with server-side rendering in mind, though

danielneal15:10:43

oh cool, that would be great if it goes in oriens as an option

anmonteiro15:10:46

so it should be quite easy to integrate

danielneal15:10:47

that’s great to hear

anmonteiro15:10:21

@danieleneal a contribution to Oriens is very welcome if you end up putting something together

anmonteiro15:10:35

I don’t have time to work on that for the moment

danielneal15:10:01

I’m guessing the best starting point is the om-next-full-stack demo you have up?

anmonteiro15:10:40

yeah, hooking it up shouldn’t be too hard, happy to answer any questions along the way

anmonteiro15:10:54

om-next-fullstack is probably a good starting point

anmonteiro15:10:24

@danieleneal BTW the Compassus tests run in Clojure too so that might be worth looking into as well

danielneal15:10:25

ah do you have a time to answer a question about the om-next-full-stack demo?

danielneal15:10:24

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

danielneal15:10:43

so a request is definitely being made

anmonteiro15:10:15

sorry I don’t understand what your question is

danielneal15:10:34

I don’t know if this is a bug

anmonteiro15:10:35

right, it’s not implemented at all

danielneal15:10:45

or if it’s just doing server side

anmonteiro15:10:56

I copied the code over from David’s om-next-demo, which doesn’t implement that

danielneal15:10:57

and the client side bit is not done

anmonteiro15:10:09

I also think you can’t add tasks

anmonteiro15:10:19

there are a few bits which just aren’t implemented

anmonteiro15:10:38

but I really don’t care because that’s not the point of the example 🙂

danielneal15:10:40

ah, ok so I should just look at the toggle of todos on and off, and use that

danielneal15:10:01

yeah - I just wanted to check that the whole end to end thing was there

danielneal15:10:09

totally doesn’t matter if some functionality is missing

hlolli18:10:28

Nice, I've been completly off the development of VR. Does this mean we could have our email inbox as a virtual object in our living rooms?