This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-05-31
Channels
- # aleph (3)
- # aws (5)
- # beginners (65)
- # boot (17)
- # cljs-dev (112)
- # cljsrn (5)
- # clojure (146)
- # clojure-austin (3)
- # clojure-dusseldorf (3)
- # clojure-italy (18)
- # clojure-norway (13)
- # clojure-russia (84)
- # clojure-serbia (5)
- # clojure-spec (24)
- # clojure-uk (84)
- # clojurescript (204)
- # css (1)
- # cursive (21)
- # data-science (3)
- # datascript (21)
- # datomic (26)
- # emacs (5)
- # euroclojure (1)
- # hoplon (8)
- # jobs (7)
- # jobs-discuss (2)
- # keechma (35)
- # lumo (92)
- # mount (1)
- # nrepl (2)
- # numerical-computing (16)
- # off-topic (10)
- # om (58)
- # re-frame (13)
- # reagent (90)
- # remote-jobs (2)
- # ring-swagger (1)
- # spacemacs (9)
- # specter (6)
- # unrepl (17)
- # untangled (56)
- # yada (2)
it seems like what you want to do is write a mutation that assoc’s your context into the app state atom and then run it in your life-cycle method with om/transact!
if your canvas context is associated with the key :ui/ctx
, you can include this in your canvas’s query
@adamvh so you're saying just go ahead an use swap!
inside componentDidMount
to assoc it to the store? i know that will work, just wondering whether there was a better way
and since this is canvas, i definitely do not want it to rerender every time i draw to it. otherwise it would always be blank! but i wouldn't be updating the context anyway, just querying it so i have something to draw to
regardless, in the interest of understanding Om.Next more, are you saying updating any keys prefixed with "ui" trigger a rerender? i assumed it was just anything under :keys
, which is stored inside a key corresponding the particular component?
if i assoc to the store directly like this: (swap! assoc-in [(keyword this) :ctx] (.getContext (aget this id) "2d"))
i'd still prefer to assoc the context actually where the component's other keys are stored rather than use the (keyword this)
hack. can anyone explain that?
well, re: the multimethod...you realize one doesn't ever need to change the context for a given canvas, right?
yes, which is why i'm putting it inside componentDidMount
instead of componentDidUpdate
i guess what i’m suggesting is equivalent to just doing swap!
to get that context into your app state
well i think you're answering my question exactly, i.e. what's the idiomatic way to assoc it using om rather than crudely with swap!
except that if you do it via om.next’s way your component doesn’t have to take the app-state as a parameter
and the way to do that would be to specialize your mutation mutlti-method for some key
your :read
multi-method is responsible for dispatching on the values of this EDN (it’s basically a parser)
well, currently i'm only passing the store to the reconciler and then adding my factory element with add-root!
i'm reading the docs for transact!
now and it seems the point is to schedule rerenders based on those keys, which obviously can't happen for the canvas's context
i guess i'm just confused about why i'd need to set up :read
and :mutate
keys just to store one static value per component created via the factory
ah ok. so that will keep it local to the component, but outside of :keys
used for props?
eh, personally i just haven't read into how the reconciler works enough. but the whole reason i use om next is because it maps onto how i used react itself pretty well
anyway, so for the record i'm just calling this inside componentDidMount
: (om/set-state! this {:ctx (.getContext (aget this id) "2d")})
and then in my function to create new canvases using the factory i'd assume: (swap! store assoc (keyword id) {:id (str id), :width width, :height height})
where "id" is probably something like canvas#
?
ah, although the problem is i'm not sure how to get the id for the component that's just loaded in order to query the context. i either need to use assign a ref to the component (with a gensym) or query the id from props
@sophiago idk if this helps but you can generate an ident and/or implement IQueryParams