Fork me on GitHub
#om
<
2016-11-03
>
fenton08:11:49

I was expecting the query to be the query from the component, namely [:me-mail]. Confused why it is null.

tobiash10:11:14

@anmonteiro using compassus 1.0.0-alpha1, it seems like a wrapper component is not attached to the om reconciler? is that by design? specifically, (compassus/current-route this) does not seem to work anymore

anmonteiro10:11:00

@tobiash I hope that's not the case 🙂 can you produce a minimal example?

anmonteiro10:11:04

@tobiash In Compassus's devcards, I tried changing this line to (c/current-route this) and it works fine https://github.com/compassus/compassus/blob/master/src/devcards/compassus/devcards/core.cljs#L405

tobiash10:11:37

ok.. i am using it with re-natal and react-native, it might be related to that then

tobiash10:11:44

i am rather new to clojurescript, what is a good starting point to produce a minimal example? the devcards?

tobiash10:11:50

since i am using re-natal, i have set :root-render on the reconciler to re-natal's custom root-render fn, I suspect it might be related to that

anmonteiro10:11:35

@tobiash if you're using React Native I suspect it might even be something else: https://gist.github.com/hugoduncan/2bd2d57b7eb42dc7b740

anmonteiro10:11:25

Om Next requires some dynamic variables to be set in the render function. Sometimes in React Native it can be messy to keep those bound

tobiash10:11:32

well I got it to work with the previous compassus version

tobiash10:11:50

its all the same code, just upgrading compassus. sorry, i was missing that context in my original question 🙂

anmonteiro10:11:26

right, but that doesn't really tell me anything until I see a minimal repro, preferrably outside of React Native

anmonteiro10:11:44

I'm not saying it's not a bug in Compassus, it could definitely be

anmonteiro10:11:13

just that you may now be hitting the React Native thing I mentioned above

tobiash10:11:10

I don't really get the point of the gist above

anmonteiro10:11:20

@tobiash could even be related to how you upgraded Compassus, there have been a few breaking changes. can you paste the part of your code where you create the Compassus application?

tobiash10:11:01

`(defui AppRoot static om/IQuery (query [this] [{:app-root [:current-user :server-status]}]) Object (render [this] (let [{:keys [current-user]} (om/props this) {:keys [owner factory props]} (om/get-computed this) route (compassus/current-route state/reconciler)] (login/login-scene {:current-user current-user})))) (defonce RootNode (sup/root-node! 1)) (defonce root-node (om/factory RootNode)) (def app (compassus/application {:routes route->component :index-route :app/home :reconciler state/reconciler :mixins [(compassus/wrap-render AppRoot)]})) (defn init [] (compassus/mount! app 1) (.registerComponent rh/app-registry "app" (fn [] root-node)))`

anmonteiro10:11:21

use 3 '`' for it to highlight properly

tobiash10:11:28

i see 🙂

tobiash10:11:50

(defui AppRoot
  static om/IQuery
  (query [this]
    [{:app-root [:current-user :server-status]}])
  Object
  (render [this]
    (let [{:keys [current-user]} (om/props this)
          {:keys [owner factory props]} (om/get-computed this)
          route (compassus/current-route state/reconciler)]
      (login/login-scene {:current-user current-user}))))

(defonce RootNode (sup/root-node! 1))
(defonce root-node (om/factory RootNode))

(def app
  (compassus/application
    {:routes route->component
     :index-route :app/home
     :reconciler state/reconciler
     :mixins [(compassus/wrap-render AppRoot)]}))

(defn init []
      (compassus/mount! app 1)
      (.registerComponent rh/app-registry "app" (fn [] root-node)))

tobiash10:11:11

i removed the actual route handling / react-native navigator stuff for now

tobiash10:11:41

ah, and sorry, this is what works. if I change it to (compassus/current-route this), it doesnt

anmonteiro10:11:15

@tobiash so you're using the navigator right?

tobiash10:11:38

normally yes, but I removed it for debugging

anmonteiro10:11:47

does it work without the navigator?

tobiash10:11:20

i dont think it is related to the navigator

anmonteiro10:11:05

@tobiash what are you using root-node! for though?

tobiash10:11:31

tbh I don't really understand what that code does, it came with re-natal when i bootstrapped the project and it worked so far, I think I will try to get it working without it and see if that causes the problem

anmonteiro10:11:48

@tobiash try this inside your AppRoot: (println om/*reconciler*)

anmonteiro10:11:14

does it print nil?

anmonteiro10:11:28

so my suspicion is confirmed 🙂

anmonteiro10:11:36

doesn't seem like a Compassus bug

anmonteiro10:11:44

but instead the bound vars problem I mentioned

anmonteiro10:11:18

@tobiash my suggestion would be to wrap your AppRoot's render in the with-om-vars macro

tobiash10:11:40

like that?:

(render [this]
  (with-om-vars this
    ....

anmonteiro10:11:26

hrm yeah, but now I'm unsure it will work

tobiash10:11:32

btw, (om/get-reconciler this) is also nil

tobiash10:11:42

that seems what the macro is doing

anmonteiro10:11:46

right so it won't work

anmonteiro11:11:22

OK let's see... does (om/get-reconciler owner) work?

tobiash11:11:08

uhoh... it doesn't, but because owner is also nil - because (om/props this) is also nil...

tobiash11:11:25

let me try wrapping with the macro again

tobiash11:11:15

nope. thats really strange.

anmonteiro11:11:00

@tobiash this is really weird, and I suspect you'll have the same problem even without the wrapper mixin

anmonteiro11:11:37

I would now start looking at what your root-render function might be doing

tobiash11:11:50

ok. thank you so far. I am trying to get it work without it, but there seems to be some dependency on ReactDOM somewhere which is not present in react-native.

tobiash11:11:45

i dont think that has anything to do with compassus though

anmonteiro11:11:49

specifically:

:root-render #(.render js/React %1 %2)
:root-unmount #(.unmountComponentAtNode js/React %)})

anmonteiro11:11:15

though I haven't messed with React Native for about a year now, and things might have changed 🙂

tobiash11:11:37

thank you!

cmcfarlen12:11:07

@anmonteiro Great progress on Compassus! I've updated to the latest and the changes really clean up the initialization nicely. Thanks for your work. The :index-route config key was definitely the way to go.

tobiash13:11:08

@anmonteiro It seems the problem was indeed caused by the re-natal root wrapper. However I am not sure what causes it and am still struggling with getting figwheel to work without the wrapper

anmonteiro13:11:52

@cmcfarlen thanks, really appreciate the feedback!

tobiash13:11:17

got it to work! thanks a lot for your help @anmonteiro! I still have to sort out the production build, but it's working with figwheel now. I'll create a minimal starter for compassus with rn then.

anmonteiro13:11:47

@tobiash awesome. link me the starter when you get one, happy to link to it from Compassus's readme

anmonteiro13:11:05

@tobiash so did you actually succeed in hooking Compassus with the RN navigator?

tobiash13:11:59

not yet with 1.0.0-alpha1, but it worked fine with the previous version

anmonteiro13:11:42

@tobiash that's great, I think some people over in #cljsrn would like to see that

tobiash13:11:46

i just found this channel today and asked about stack traces - because thats my main problem with cljs and rn - its very hard to debug stuff

tobiash13:11:11

but yeah, I'll be happy to extract a sample from my application

anmonteiro13:11:04

@tobiash Mike Fikes has a few videos about debugging CLJSRN apps. this one, for instance, https://www.youtube.com/watch?v=2DfYsgOYpW4

tobiash13:11:14

although there might be some ramifications to dropping the re-natal.support package. but so far reloading seems to work

tobiash13:11:28

thanks, I'll try that out later. I think react-native already uses react-redbox to do something like this automatically, but there are some cases where re-natal's figwheel bridge code just swallows exceptions. And to me it looks difficult to get these errors back to react-native so they can be displayed properly.

tobiash13:11:06

so then very often you just get a dead-end stack trace to some eval() call

alpheus13:11:55

Is it a mistake to call om.next/transact! in a component's render method?

levitanong14:11:37

@alpheus by that do you mean calling it “naked”, resulting in it being invoked every re-render? Or do you mean calling it in a callback inside the render method?

anmonteiro15:11:23

@dnolen minor thing, but you might have forgotten to push the alpha47 tag and it's confusing some people

anmonteiro15:11:43

because it's on Clojars but not GitHub

levitanong16:11:28

@anmonteiro are you aware of any issues with dom/render-to-str and queries with query params? I’m working on server side stuff. I’ve logged the appropriate read function, and the params are as expected. I’ve logged the query of the app root, and it’s as expected. But somehow it isn’t going through to the render function if I use dom/render-to-str.

anmonteiro16:11:58

@levitanong not aware, but happy to look at a minimal failing example

levitanong16:11:28

@anmonteiro alrighty, will work on one

levitanong17:11:39

@anmonteiro Another question, as I work on the minimal example: Is there a known issue when trying to om/set-query! a component (returned by om/add-root!) and then dom/render-to-str? I have a semi-case below.

(let [r (om/reconciler …)
      c (om/add-root! r App nil)
      q (om/set-query! c {:params {:a 1}}) ;; :a was previously nil
      html-string (dom/render-to-str c)] ;; I had assumed that it would be okay to do this, because the line above should have mutated c. But apparently not, as the rendered string is acting as if :a were still nil.
  …)

anmonteiro17:11:28

@levitanong yeah I don't think that's gonna work

anmonteiro17:11:52

we never actually reconcile changes on the server-side

anmonteiro17:11:34

my rule of thumb here is that we should follow whatever React does

anmonteiro17:11:03

i.e. if in plain React you can setState when doing server-rendering we should implement that too

levitanong17:11:09

@anmonteiro so in this case, the only way around it is to keep things (like current-thing) in state, and not in query params, no?

anmonteiro17:11:41

@levitanong before jumping to workarounds we should see what React does and try to match that behavior

anmonteiro17:11:11

once we do that, we can think of alternatives if we still have a problem

anmonteiro17:11:44

@levitanong feel free to open an issue if you don't want to investigate what React does

anmonteiro17:11:10

I'm busy right now, but I'll get to it eventually

levitanong17:11:14

@anmonteiro Haha, I’ll open an issue 😛 React’s code base is way out of my league I think.

anmonteiro17:11:02

@levitanong I didn't mean going through React's codebase

anmonteiro17:11:38

you can infer what they do by creating an Om Next example that calls set-state!, and rendering that in Node.js

levitanong17:11:27

@anmonteiro Hmm. Would it have to be node.js?

anmonteiro17:11:44

any javascript engine will do

anmonteiro17:11:05

@levitanong anything that can call ReactDOMServer.renderToString

anmonteiro17:11:30

doesn't have to be Node.js, sorry

levitanong17:11:13

Hmm. If it’s that, then perhaps I can work on it. It’s late here though, so I’ll do it tomorrow or something. I’ll open an issue for reference. 🙂 Thanks for the replies, @anmonteiro!

anmonteiro17:11:19

I did it all the time when I implemented the server-side rendering stuff 🙂

anmonteiro17:11:35

esp. to get the react-id stuff right

levitanong17:11:00

So I’d have to compile the om.next example into javascript, or would simply using React with some set-state! suffice?

anmonteiro17:11:25

@levitanong just run this in a REPL:

(require '[om.next :as om] '[om.dom :as dom] 'cljsjs.react 'cljsjs.react.dom.server)

(defui Foo
  Object
  (initLocalState [this]
    {:foo 0})
  (componentWillMount [this]
    (om/update-state! this update-in [:foo] inc))
  (render [this]
    (dom/div nil (om/get-state this :foo))))

(dom/render-to-str ((om/factory Foo)))

anmonteiro17:11:57

and see if :foo is 0 or 1 🙂

levitanong17:11:14

lol alright then, hang on

levitanong18:11:40

@anmonteiro Had some trouble with cider and its dependency weirdness, so I decided to just run it off my boot task. I did indeed get 1. <div data-reactroot="" data-reactid="1" data-react-checksum=”-2048323701">1</div>

anmonteiro18:11:20

@levitanong hrm right, but you'll also get 1 in Om Next right now...

anmonteiro18:11:31

my example doesn't illustrate what you want to accomplish

anmonteiro18:11:45

I'll have to think about it some more, but I think we should support it

anmonteiro18:11:51

thanks for raising the issue

levitanong18:11:07

Hurrah! \o/ My pleasure.

tobiash18:11:42

@anmonteiro My very simple example https://github.com/tobiash/rn-compassus-example - now it works even if the re-natal support - not entirely sure why 🙂

whitecoop19:11:39

FWIW, re: my previous post (https://clojurians.slack.com/archives/om/p1478052545005389). I figured it out. componentDidMount is the right approach for getting the DOM node for CodeMirror's use, but when passing this to the component that was using CodeMirror I made the mistake of calling (<factory-function> this) rather than (<factory-function> (om/props this)). Subtle, but apparently essential. After doing some testing directly in React.js to eliminate factors and figure this out, I also got a better intuitive sense of the divide between React and Om Next which was helpful. Sounds obvious saying it now, but it's true. I recommend it for anyone else learning Om Next. simple_smile Thanks again to everyone who's worked on Om Next. It's a high hill but a great tool.

currentoor21:11:22

@anmonteiro I think I figured it out, it’s not perfect but I think this is as good as it’s going to get. https://gist.github.com/currentoor/576c25b80e580ef18553087176d94cfd

currentoor21:11:46

based on this code

anmonteiro21:11:41

I wonder if you need to override function though

anmonteiro21:11:57

my idea would be: [(om/tempid "")] in the routes

currentoor21:11:11

i think i have to because the code i linked in bidi, though i’d love to be wrong about that

anmonteiro21:11:17

then extend the PatternSegment protocol to om.tempid.TempId

anmonteiro21:11:44

in transform-param, call om.next/tempid

anmonteiro21:11:51

I think that would work

anmonteiro21:11:06

and you wouldn't need to monkey-patch bidi

currentoor21:11:36

oh yeah it totally works with (om/tempid “”) in the routes, i did that first

currentoor21:11:58

but i sort of hate the way that looks

anmonteiro21:11:46

yeah, your call

anmonteiro21:11:59

I think both work

currentoor21:11:13

maybe bidi will be open to making the function types more extensible?

anmonteiro21:11:18

this way you need to watch out for breakages upstream

currentoor21:11:23

i’ll ask in the issue

anmonteiro21:11:30

that would be the right thing to do IMO

currentoor21:11:47

so while you’re here i have a question

currentoor21:11:07

tempids, why are they a defrecord in clj but a deftype in cljs?

anmonteiro21:11:13

no idea, is there an implication for you?

currentoor21:11:18

nope just curious

anmonteiro21:11:12

makes for a lot less code too 🙂

tobiash22:11:23

whats a good pattern for hooking push-based remotes to om.next? say I have a screen in my component that displays a stream of chat messages - should i subscribe in componentDidMount and transact! each event in the listener? or is there a more declarative approach using remotes?

anmonteiro23:11:13

@tobiash you can call om.next/merge! to side-load novelty

anmonteiro23:11:38

affected components will be re-rendered

anmonteiro23:11:42

(based on their query)

currentoor23:11:22

I believe my approach was more declarative than using react life cycle methods.

tobiash23:11:36

thank you, very interesting

currentoor23:11:14

np, hope it helps!

sineer23:11:24

Would it be "O.K" to do something like (om/get-query (om/ref->any :home/foo)) ? I see ref->any macro marked as dev helper... I'm thinking about using ident to locate an instance of a component and access it's props or else I have to build my own ident/instance map?

sineer23:11:23

@currentoor very cool article! Thank you very much for writing it 🙂