om

Please ask the channel first, not @dnolen directly!
adamvh 2017-05-31T01:33:01.399697Z

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!

adamvh 2017-05-31T01:33:54.406352Z

if your canvas context is associated with the key :ui/ctx, you can include this in your canvas’s query

adamvh 2017-05-31T01:36:40.427795Z

and then om will know to re-render each time you bang on your canvas with a mutation

sophiago 2017-05-31T01:39:22.448318Z

@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

sophiago 2017-05-31T01:41:32.465090Z

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

sophiago 2017-05-31T01:43:24.479913Z

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?

sophiago 2017-05-31T02:00:32.614706Z

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?

adamvh 2017-05-31T02:14:52.721841Z

you wouldn

adamvh 2017-05-31T02:15:12.724150Z

‘t assoc it to the store, you would would do something like

adamvh 2017-05-31T02:16:01.729871Z

call (om/transact! [(assoc-ctx-to-store) {:ctx ctx}])`

adamvh 2017-05-31T02:16:30.733288Z

and then you would have a big ‘ole multi-method which i’ll call mutate

adamvh 2017-05-31T02:17:06.737318Z

and this multi-method will dispatch on the symbol ‘assoc-ctx-to-store

sophiago 2017-05-31T02:17:23.739365Z

what is "assoc-ctx-to-store" supposed to represent?

adamvh 2017-05-31T02:17:43.741500Z

it’s just a symbol inside a syntax-quoted form

adamvh 2017-05-31T02:18:07.744357Z

that om.next will use as a dispatch key for calling your mutation multi-method

sophiago 2017-05-31T02:18:23.746167Z

well, re: the multimethod...you realize one doesn't ever need to change the context for a given canvas, right?

adamvh 2017-05-31T02:19:19.752750Z

right, so you probably only ever set that context once

sophiago 2017-05-31T02:19:50.756306Z

yes, which is why i'm putting it inside componentDidMount instead of componentDidUpdate

adamvh 2017-05-31T02:20:34.761783Z

i guess what i’m suggesting is equivalent to just doing swap! to get that context into your app state

adamvh 2017-05-31T02:21:05.765477Z

so yea you’re right that seems like the thing to do here

sophiago 2017-05-31T02:21:18.767065Z

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!

adamvh 2017-05-31T02:21:36.769166Z

except that if you do it via om.next’s way your component doesn’t have to take the app-state as a parameter

adamvh 2017-05-31T02:22:03.772260Z

and the way to do that would be to specialize your mutation mutlti-method for some key

sophiago 2017-05-31T02:22:03.772301Z

hmm?

sophiago 2017-05-31T02:22:25.775035Z

i still have no idea what you mean by "mutation multimethod"

adamvh 2017-05-31T02:22:39.776695Z

ah, ok, so time to back up then

sophiago 2017-05-31T02:22:48.777750Z

i don't understand why this calls for using a multimethod at all

adamvh 2017-05-31T02:25:45.798354Z

when you create an om.next reconciler, you pass it a map with keys :read and :mutate

adamvh 2017-05-31T02:26:14.801901Z

and the values associated with these keys will be two multi-methods

adamvh 2017-05-31T02:26:57.807056Z

your components will generally implement om/IQuery and return some EDN

adamvh 2017-05-31T02:27:50.813598Z

your :read multi-method is responsible for dispatching on the values of this EDN (it’s basically a parser)

sophiago 2017-05-31T02:28:15.816513Z

well, currently i'm only passing the store to the reconciler and then adding my factory element with add-root!

sophiago 2017-05-31T02:29:28.825227Z

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

sophiago 2017-05-31T02:33:24.854250Z

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

adamvh 2017-05-31T02:35:27.868465Z

ah, i think you want om/set-state!

adamvh 2017-05-31T02:35:37.869671Z

that’ll let you define the context as state local to your component

sophiago 2017-05-31T02:36:06.872992Z

ah ok. so that will keep it local to the component, but outside of :keys used for props?

adamvh 2017-05-31T02:36:24.875196Z

yep

sophiago 2017-05-31T02:36:26.875405Z

yeah, that sounds perfect (and, sadly, obvious)

adamvh 2017-05-31T02:36:49.878106Z

om next is far from obvious to me anyway

sophiago 2017-05-31T02:38:17.888404Z

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

sophiago 2017-05-31T02:38:40.891064Z

i.e. using the top level API vs. JSX, the latter being a bit more how reagent works

sophiago 2017-05-31T02:39:40.897838Z

anyway, so for the record i'm just calling this inside componentDidMount: (om/set-state! this {:ctx (.getContext (aget this id) "2d")})

sophiago 2017-05-31T02:42:33.917847Z

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#?

sophiago 2017-05-31T02:43:17.922916Z

or actually maybe that'd be better with set-state! and the factory itself?

sophiago 2017-05-31T02:45:50.940887Z

idk. again, swap! is what i've used historically with factories

sophiago 2017-05-31T02:55:17.007583Z

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 2017-05-31T03:07:44.097520Z

ok, snippet updated. i think this is correct...

sophiago 2017-05-31T03:20:28.183963Z

apparently not 😞

2017-05-31T04:05:15.479627Z

@sophiago idk if this helps but you can generate an ident and/or implement IQueryParams

2017-05-31T04:05:34.482134Z

The former can take props as parameters to generate a query argument per instsnce

2017-05-31T04:05:37.482413Z

*instance

2017-05-31T04:05:40.482741Z

Rather than per class

sophiago 2017-05-31T04:56:24.813732Z

@nikki the problem currently is it's not generating new canvases at all. i need to compare it to a version of the same code i have that generates other ui components similarly to troubleshoot

2017-05-31T05:01:02.845444Z

:thinking_face:

🤕 1
dehli 2017-05-31T12:13:18.040026Z

Can you set data attributes on elements when using om next?

dehli 2017-05-31T12:18:08.107447Z

^ looks like you can do it with:

(dom/div #js {:data-example ""})

gws 2017-05-31T20:15:03.029613Z

Any idea why a child component having a join with an ident key would not cause a remote (or any) read for that ident when the root component's query is updated to include said child?