Fork me on GitHub
#clojurescript
<
2016-07-19
>
krchia03:07:40

i’m not sure how best to express it, but how do i use “pointers”?

krchia03:07:31

i have an om component, and a map {:nodes .. :links ..}

krchia03:07:24

links is a vector of node to node connections, and i need links to contain a pointer to the node as the node’s x and y values changes

krchia03:07:54

i’m trying to work with d3, if it’s relevant here

krchia03:07:28

what happens when i declare a new link is that it just uses the current value of x and y, and doesn’t update when the node’s coordinates change

krchia03:07:21

i’m not even sure that pointers are the right term to use, and i haven’t been getting good results from searching “clojurescript pointers"

mj_langford03:07:52

reference is the term you’re talking about in a jvm language

mj_langford03:07:24

when using om, you have one atom that has app state

mj_langford03:07:43

what you need to keep is the path to that node

mj_langford03:07:47

the path is data

mj_langford03:07:06

then in your component, the render function should continue to update as you change the app state

krchia03:07:06

i’ve tried using app-state and local component state

mj_langford03:07:22

are you updating the appstate as the node changes?

krchia03:07:56

and i’ve checked, in every tick in IDidUpdate my node’s x coordinate changes

krchia03:07:19

but the link’s reference to the node x is still the same (actually it does change, but at some point it stops reflecting the current value)

krchia03:07:24

sorry if that’s confusing

krchia03:07:04

at this point, i’m not sure if it’s a d3 or om error

mj_langford03:07:40

what are you doing in your IDidUpdate handler

krchia03:07:06

please excuse all the printlns

mj_langford03:07:51

that’s helpful!

krchia03:07:16

the uncommented (.log js/console ..) is the part where i can see the link reference to the node is not the same

mj_langford03:07:46

are you seeing your IDidUpdate being called?

krchia04:07:32

there are printlns littered there, and they’re called just about the same as the tick function initialized in IDidMount

krchia04:07:02

thanks for telling me the right term is reference, but it seems like i need to be a little clever about googling the right terms - all i’m getting is API/documentation hits 😅

mj_langford04:07:46

You aren’t looking for the term cursor are you?

krchia04:07:06

oh i finally got it to work, but the code is UGLY AS FUCK.

krchia04:07:21

nope, i’m aware of cursor, but i’m not sure it’s what i need here

mj_langford04:07:27

glad you got it working. Ugly is merely a first step to good

krchia04:07:56

and getting it to work is sometimes an impediment to understanding, because after spending hours on this i’m not sure i want to spend more time getting to understand this

mj_langford04:07:29

that’s what other days are for

krchia04:07:19

apparently, after an event that adds a node to the state, i have to reinitialize the links with the same declarations

krchia04:07:40

i’m not sure why this is so

krchia04:07:12

what i meant is at the start i do this: (om/set-state! owner :links (clj->js [{:source (get-node owner 0) :target (get-node owner 1) :left false :right true} {:source (get-node owner 1) :target (get-node owner 2) :left false :right true}]))

krchia04:07:27

and i need to do the same in IDidUpdate everytime i add a new node

krchia04:07:59

it obviously won’t scale if i add new functionality to add new links, but i can use this to figure out what’s going on at least

krchia04:07:05

thanks @mj_langford 🙂

mj_langford04:07:56

I do very little om, but glad I was at least a :duck:

rohit07:07:33

@anmonteiro, for me, the jsdoc is only emitted when defined with the function in the protocol and not in the implementation. maybe i am doing something wrong.

rohit07:07:50

here is the code I tested with:

(defprotocol P
  (^{:jsdoc ["@type {*}"]} foo [this])
  (bar-me [this]))

(deftype Foo [a b c]
 P
  (^{:jsdoc ["@type {*}"]} foo [this] a)
  (bar-me [this] b))

ajchemist08:07:18

there's some weird bug(?) that I've just experience. when I name a wrapper namespace of cljsjs.mousetrap, called my.cljsjs.mousetrap, and I require my.cljsjs.mousetrap in someplace like cljs.user, then every Var inside my.cljsjs.mousetrap is undeclared, can't be used. any idea? is this another namespace clash issue?

thheller08:07:30

I don't quite understand what you mean by "when I name a wrapper namespace of cljsjs.mousetrap, called my.cljsjs.mousetrap"?

thheller08:07:32

what does you ns look like?

ajchemist08:07:17

@thheller:

(ns my.cljsjs.mousetrap
  (:require
   [cljsjs.mousetrap]))

thheller08:07:22

and your require?

ajchemist09:07:36

(ns user.core
  (:require
   [my.cljsjs.mousetrap :as mousetrap]))

thheller09:07:41

and you def something in my.cljsjs.mousetrap and you cannot use it as (mousetrap/something) ?

mikethompson09:07:59

I'm preparing a .cljs file for transition to .cljc. In the .cljs I find (when ^boolean js/goog.DEBUG ... and I'm wondering how to transform that ... what's the standard way in clojure to know about production vs development builds? (I know almost nothing of the java/clojure world). Is there a direct translation or is it complicated?

thheller09:07:43

@ajchemist: that should not be a problem, are there any warnings generated anywhere?

thheller09:07:00

and how do you use the Mousetrap object?

ajchemist09:07:08

----  Compiler Warning on   <cljs form>   line:1  column:1  ----

  Use of undeclared Var my.cljsjs.mousetrap/boot!

  1  mousetrap/boot!
     ^--- 

----  Compiler Warning  ----

thheller09:07:30

@mikethompson: clojure does not make a distinction between production and development

ajchemist09:07:31

well, this is not about Mousetrap, just namespace thing though

ajchemist09:07:25

(defn ^:export boot! []
  (when (and (exists? js/Mousetrap)
             (oget js/Mousetrap "prototype" "handleKey"))
    (oset js/Mousetrap "prototype" "handleKey" handle-key)
    (mlog/debug "js/Mousetrap has booted.")))

thheller09:07:55

and that is in my.cljsjs.mousetrap?

ajchemist09:07:38

@mikethompson: clojure can have aot, direct-linking and elide-meta optimization for production I think.

thheller09:07:23

@mikethompson: you want something like environment variables or something you set up yourself

mikethompson09:07:08

okay thanks. Yeah, I guess I'm wondering what method is used when you want to remove code which belongs in dev builds but not in production

thheller09:07:37

same way you are doing in cljs

thheller09:07:48

just not using the goog.DEBUG object 😉

thheller09:07:46

I usually have a my.app.env namespace

thheller09:07:12

with a (def DEBUG (is-this-debug?))

thheller09:07:36

is-this-debug? looks at a environment variable or something similar

thheller09:07:44

@ajchemist: not sure what is happening, looks ok from the snippets you showed

vikeri09:07:24

Have anyone mocked namespaces in clojurescript? I’m testing a re-frame app in React Native and would like to test the business logic in node. RN needs a lot of babel transforms and stuff, so if I include any reference to code that includes require calls to RN the code does not work in node. Hence I would like to mock out the namespaces that call RN since I wont test them anyway. Any ideas?

anmonteiro10:07:52

@rohit: exactly, that's what I'm seeing too

rohit10:07:32

@anmonteiro: it sort of makes sense to me. you always call the function in the protocol. it then delegates to the call to the particular function.

anmonteiro10:07:42

@rohit: there are some Closure directives like @nocollapse that would make sense per implementation

rohit10:07:24

@anmonteiro: actually don’t know enough about jsdocs to comment on that.

bhauman16:07:13

I'm thinking about adding a switch to figwheel, that will delete ns definitions in client memory that have been deleted from the original source file...

bhauman16:07:20

this could add much needed sanity to the dev process, in that things that reference deleted definitions will fail fast

bhauman16:07:42

This is normally caught by compiler warnings. But there are cases where you can still use deleted code without warning.

nha22:07:29

anyone using sente 1.9.0 ? It seems I do not get the :chsk/state event client-side.