This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-07-19
Channels
- # admin-announcements (2)
- # aws-lambda (3)
- # beginners (66)
- # boot (61)
- # cider (1)
- # cljs-dev (17)
- # clojure (100)
- # clojure-austin (4)
- # clojure-brasil (1)
- # clojure-canada (8)
- # clojure-quebec (6)
- # clojure-russia (48)
- # clojure-sg (6)
- # clojure-spec (37)
- # clojure-uk (61)
- # clojure-ukraine (2)
- # clojurescript (80)
- # core-async (13)
- # cursive (20)
- # datascript (37)
- # datomic (2)
- # defnpodcast (4)
- # emacs (5)
- # funcool (3)
- # hoplon (11)
- # jobs (7)
- # juxt (26)
- # lein-figwheel (48)
- # leiningen (3)
- # luminus (3)
- # om (34)
- # om-next (5)
- # onyx (5)
- # protorepl (6)
- # re-frame (10)
- # reagent (9)
- # rethinkdb (16)
- # ring-swagger (5)
- # spacemacs (14)
- # specter (54)
- # untangled (36)
- # vim (75)
- # yada (1)
i’m not sure how best to express it, but how do i use “pointers”? i have an om component, and a map {:nodes .. :links ..} 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 i’m trying to work with d3, if it’s relevant here 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 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"
@krchia: Since Clojure(Script) has immutable data structures, when "x and y values change" what you get is a new data structure with updated elements.
So even if you had a "pointer" to the original data structure, that isn’t going to help you.
I don’t know what to elaborate on.
Clojure’s immutability means your x and y values don’t "change" — you get a whole new structure with updated elements.
The way folks generally deal with that is by providing repeatable navigation into data structures — so it works with each new structure (i.e., what is generated by "changing" the values contained in it).
What is in your :nodes
element in that map?
apparently, after an event that adds a node to the state, i have to reinitialize the links with the same declarations - i’m not sure why this is so
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
Immutability is "why this is so"
Because the nodes don’t "change", what you get is just a new nodes data structure. So links references the original unchanged data structure.
A path into a data structure, e.g., [:left 0 1]
such as an argument to get-in
.
Am I right that your links
structure is always built as a set of pairs of source/target for each node pair from 0 .. n-1 (i.e,. the last link is source (n-1) / target (n)?
So you could have links from node 0 to node 1 and from node 0 to node 2?
so my attempt at writing a proper reference i.e. (defn get-node [owner idx] (aget (:nodes (om/get-state owner)) idx)) isn’t the proper way?
i suspect it has something to do with the sequence of d3 calls with .. enter append exit remove when i add something to the node map
when you do this (clj->js (conj (js->clj (om/get-state owner :nodes)) {:id lastnodeID …
you are converting the JS array to a Clojure vector (a brand new data structure) and then conj’ing the new element, producing another new data structure, then converting that to JS and replacing the old nodes array with this completely new one
I think if you change that to (.push (om/get-state owner :nodes) (clj->js {:id lastnodeID :x x :y y}))
then the old nodes array will be preserved I think.
(and don’t call set-state!
on it)
OK so try (let [nodes (om/get-state owner :nodes)] (.push nodes (clj->js {:id lastnodeID …})))
The push() method adds one or more elements to the end of an array and returns the new length of the array.
Remember that I’m not suggesting you do anything with the result of calling .push
I’m suggesting calling it purely for its side-effects.
That’s why I said do not call set-state!
on the result.
Basically your nodes is a JS array, so you have to work with it as a mutable structure — not a cljs structure.
but i think the pain i faced today and yesterday might just persuade me to change my mind about that
Clojure rewards careful thinking 🙂
I’m out for the night. Have fun with D3!
I've been using Go for six months now; but still my heart is saying that probaly I should spend the same amount of time with Clojure
there's something about the Go language that I don't like. Sometime I feel Gophers tend to over simplify stuffs