Fork me on GitHub
#om
<
2015-12-06
>
anthgur01:12:55

I might be way off on this but I think this is an example of how routing could be done https://gist.github.com/anthgur/2cddf81e04ea78f372c6

noonian01:12:07

@anthgur: that strategy definitely works. I’m not sure your example would work as is but I'm using that same idea for routing and thats how @jdubie’s routing example used to do it.

artemyarulin09:12:54

Does anybody thought how to create independent components (think library of UI controls for example) - query nicely encapsulates reads (like components needs :title and doesn’t care how to get it) but I’m a bit stuck with state changes. Possible way could be that the component will provide a mutation function which user can call from the own mutate function

anmonteiro10:12:43

@artemyarulin: If you mean a library of UI controls, I'd say components are stateless so they don't need to implement IQuery

anmonteiro10:12:03

The queries would lie in your stateful components

artemyarulin10:12:42

well in the best case - yes

artemyarulin10:12:45

but I guess it’s not all the time possible, sometimes component would benefit from the state. Actually my question is more general - I can create general read function which just returns keys (especially using ident) and cover most of the cases. But with mutate I have to specify quite a lot. I often found myself editing components - then mutate function, then component again, then mutate and so on

artemyarulin10:12:17

would be cool if I would find a way how to encapsulate component mutate function inside the component itself

anmonteiro10:12:17

Let me give you an example, since you mentioned a :title prop. Your (generic) title component would implement whatever styles and behavior you'd need and render om/children. You'd simply need to pass an element to this generic component, but the :title prop would be queried in your stateful component. Is this clear?

anmonteiro10:12:00

If you want independent components then they shouldn't query anything, I'd say

anmonteiro10:12:57

If you introduce a query then you're tying them to an application state which doesn't make them generic anymore

artemyarulin10:12:28

Well :title it’s a bad example. Imagine textbox which has to maintain the internal state (like number of characters and who knows what). Update the state using events on_change on_number_of_characters changes is not a choice

anmonteiro10:12:14

Didnt get the part about "who knows what"

anmonteiro10:12:36

But maintaining the number of characters sounds to me like local state

artemyarulin11:12:18

local state would work, for some reason I forgot about it

artemyarulin11:12:52

with local state communication between components would be implemented using events (computed props) like on-number-of-character-changed = #(fn…) My original intention was to make communication using state and state observing.

anmonteiro11:12:22

That would be complecting things

anmonteiro11:12:20

Local state and computed exist for that purpose

artemyarulin11:12:11

Yep. OK, thanks in any case, I’ll think about it

jgdavey18:12:54

@dnolen: Is there any reason why this here https://github.com/omcljs/om/blob/master/src/main/om/next.cljs#L955 assertion message says must be “ref or keyword”, but the condition is only (if (keyword? k))? I’m getting an error when the remote returns a map with an ident as a key.

dnolen18:12:01

@jgdavey: that just seems unrelated to your problem

dnolen18:12:13

idents are handled by default-merge-idents

dnolen18:12:48

idents are handled by :ref->components index

dnolen18:12:03

so if you fell through that then than no component exists with that ident

dnolen18:12:19

all of this is plumbing details

dnolen18:12:28

and sheds no light on what you are actually trying to do

jgdavey18:12:29

Hmm. The remote returns a map that looks like {[:post/by-id 3] {:post/title “Foo”}}

dnolen18:12:17

so does a component with that ident exist?

jgdavey18:12:30

But, the actual read dispatched method returns just the map of attrs

jgdavey18:12:20

No, this is the initial query: Find post with this id, and grabs these attrs (as defined by sub-components)

jgdavey18:12:52

So, no component exists yet

dnolen18:12:59

so it sounds to me like you trying to read a key when you don’t need to

dnolen18:12:53

but let me double check

jgdavey18:12:52

It looks like the same thing, even when I hard-code the om/Ident of the top-level component.

dnolen18:12:00

so I think I know the problem

dnolen18:12:22

there’s really no reason to throw an error here vs. just returning the empty set if nothing is found

jgdavey18:12:22

Okay, and then it would fall through in this case?

dnolen18:12:18

fixed in master

jgdavey18:12:20

Cool. Thank you!

dnolen18:12:40

the problem was that the default behavior is what you normally want

dnolen18:12:54

if the top level keys are mapped to components you want to re-render

dnolen18:12:07

but of course in the case where you haven’t rendered them yet, this is not going to work

jgdavey18:12:41

That makes sense. I’ll try building from master :thumbsup:

tony.kay19:12:43

I’ve put my tutorial in progress up live on github pages. Lots to do still, but if you’re just wanting to play with query simulations and other live bits, it works well: http://awkay.github.io/om-tutorial The section on queries is where @hmadelaine added in a nice edn editor for me, as mentioned here the other day.

dnolen19:12:55

@tony.kay: ok if I tweet about it or you holding for a bigger announce?

tony.kay19:12:29

It is a long way from done…people were asking questions about bits that are there, and I wanted to just be able to link them. In particular, the section on queries is helpful for that.

tony.kay19:12:49

fine with a tweet…don’t have plans for a big announce as such…just need to note that it is vey much not done.

tony.kay19:12:41

Also, it is meant to be run locally (so you can edit the real source of the tutorial), so linking to the github project might be appropriate.

dnolen19:12:54

@tony.kay: still very cool stuff, I’m sure many people will find it useful even in it’s current form

tony.kay19:12:44

Thanks, and I agree. That is why I mentioned it. I had gotten a question on my youtube overview about queries, so I just wanted to be able to point them at a link where they could play.

dnolen19:12:44

@tony.kay: do you have a twitter handle you use?

anmonteiro19:12:30

@tony.kay: awesome work; I'm sure this will be very useful for a lot of people. myself included. going to read through all of it

rwoody19:12:25

very nice, thanks

env20:12:01

@tony.kay thanks for sharing, this is quality stuff and is really helping me study and solidify om next concepts. working smoothly, mobile and offline, as i tear through the interactive examples on my mobile riding the subway.

artemyarulin20:12:36

I guess I’ve heard somewhere that using closures in the transact! calls is not a safe thing. Is it? Or I remember it wrong?

tony.kay20:12:40

@dnolen: I do not…I am disturbingly unreachable in the world. don’t even carry a cell, nor do I have a home phone. Computer off? stone age simple_smile @anmonteiro: @env Thanks for the feedback. Glad to know it is working on mobile. I’m reworking a lot of it, and more exercises are coming…

dnolen20:12:39

@tony.kay: haha, for the best.

tony.kay20:12:12

@artemyarulin: transact takes data…I guess you could technically pass a lamda as a parameter. The unsafe thing is to do side-effect things in your mutation functions outside of the action thunk

tony.kay20:12:24

but even passing a lambda does not make sense

tony.kay20:12:45

because you are not supposed to know if it is a remote mutation, and if it were…well, code isn’t very serializable

artemyarulin21:12:32

makes sense. Thanks!

thosmos22:12:53

@tony.kay: your tutorial looks great! thanks for sharing!

maackle22:12:32

@tony.kay I’m a beginner, going through your tutorial now, it’s very helpful and well-organized. Thanks!

maackle22:12:07

seems that I picked the perfect time to join this channel simple_smile

thosmos22:12:47

Here's a demo of the Components, Identity & Normalization tutorial that has two sections, one with the default map db, and one with a Datascript db: https://github.com/thos37/om-experiments/tree/refs

domkm22:12:25

I looked at om.next about a month ago; it seems to have changed substantially since. Any recommended reading/projects if I want to use it with Datomic, DataScript, and streaming server updates (tx datoms pushed via Sente)?

thosmos23:12:45

@domkm that's the architecture I'm aiming for as well, but I'm unaware of any working end-to-end example for it.

domkm23:12:48

@thosmos: Do you know of any partial examples?

thosmos23:12:34

@domkm: nothing om.next specific other than little client-only examples like the one I posted above or the datascript integration tutorial. https://github.com/datodev/dato is very interesting. tonsky has some good examples for streaming datoms like https://github.com/tonsky/datascript-transit http://tonsky.me/blog/datascript-chat/ http://tonsky.me/blog/acha-acha/ Those use other react wrappers, so would need to be adapted to om.next

domkm23:12:15

@thosmos: Okay, thanks. simple_smile Good luck on your project.

thosmos23:12:55

@domkm: My pleasure. Are you aware of anything relevant?

domkm23:12:17

Nope. I'm just starting to look into this again.

thosmos23:12:47

Cool, well, please keep me updated if you find something good. 😉