This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-11-21
Channels
- # admin-announcements (14)
- # aws (27)
- # beginners (10)
- # boot (152)
- # cljsrn (3)
- # clojure (93)
- # clojure-hk (4)
- # clojure-russia (35)
- # clojure-switzerland (1)
- # clojurecup (1)
- # clojurescript (146)
- # core-async (23)
- # cursive (2)
- # devcards (1)
- # editors (1)
- # hoplon (28)
- # jobs-rus (4)
- # ldnclj (3)
- # leiningen (3)
- # luminus (2)
- # off-topic (4)
- # om (174)
- # re-frame (1)
- # slack-help (5)
http://23.km,M mbNNbjv
cat on keyboard detected ^
FYI, my tutorial is becoming a full-blown application dev tutorial, not just remotes, so I’ve renamed it. I updated the link earlier, but just noting: https://github.com/awkay/om-tutorial
'When writing a backend parser you will usually supply env yourself.' is he talking about a server-side parser or a client side parser that talks to a remote backend?
When he says backend parser he means the server-side parser. For instance, you might provide a database connection in your server-sider parsers env.
got ya, thanks
i translated the simple List-Tutorial to datascript. In my apps, the root gets the :db/id 0
(as far as i know, this is not possible in datomic, but in datascript it is a nice solution). https://gist.github.com/ThomasDeutsch/0080e4ec0a0a21bec943
can anyone give me some tips on keeping datascript/datomic in sync between server and client?
im trying to work out how to update my client state with data returned from a remote, i see the api call returning the data but the default send cb doesnt seem to do anything with it
@nowprovision: but that is also true if you want a client parser that acts as a remote, for example, if you use a cloud service (like http://Parse.com, Firebase, ...), you can write a full parser on the client side that translates the calls to the cloud service, on this case you probably would like to provide some env too (like the cloud service connection)
I'm ready to try out path optimization as well, same issues as @jdubie. If path optimization has Ident use as a prerequisite, is there a solution for datascript?
seems like i need to implement either merge or merge-tree as the default implementation work for atoms?
does anyone have an example?
@danielstockton: Yeah, cb has no idea about Datascript. You will have to write merge algorithms yourself. Plug in your own merge-tree that dumps to the console, and go from there.
@jethroksy: well there ya go encouraging me to do even more work 😉
thanks for the tips, just started doing that, it does look like i can just d/transact the vector response
so looks like the return value from merge-tree replaces the reconciler :state?
so it should return the datascript conn
and I may not be exactly correct on any of this…you can plug in an override for merge, merge-tree, merge-ref, and migrate. I’d have to read the source to remember how they all connect; however, you will need to handle anything they do to the DB when using DS.
at the moment im getting assertion failures (conn? conn)
merge-tree isd/transact!ing the conn and returning conn
presumably the assertion error is due to subsequent reads and my state is no longer a datascript conn
state is always an atom (which is what DS uses as conn)…nothing changes that (nor can it) in reconciler. Immutable data and all. That is why it is an atom.
note, merge-ref is called, too…you might want to stub that and make sure it isn’t corrupting things
Hi! What would be the proper way to set the query parameters of a dynamically created (om.next) component? Do I need to use om/set-query!
for that, or is there an argument that I can pass to the factory function?
yep, the default implementation looks like it would
is there a simple explanation for the purpose of merge, merge-tree and merge-ref?
To any lurkers that like making SVG graphs from code: I’m working on that tutorial, and it would be awesome to have a devcard that could graph the Om AST so we can have a card where you can play with queries and see the resulting tree. Message me directly if you like playing with vizgraph-like stuff and would like to give it a try.
@hans: set query should be done on a component, so anywhere you have a reference to the component is fine
@tony.kay: ah, ok, so i'll just set it right after i've created the component, in the caller. thanks!
you typically change a query in response to some event. You can get components from the indexer if you need to find one
maybe i'm doing things backward. i'm writing a (scrabble) game and i was thinking that each of the places on the board would be one component, that'd know its coordinate so that its query function would find the state of the place.
In general, some sub-component will fire off something, and you’ll want a parent to modify some upper query. Use callbacks for that.
OH. I see.you’re trying to change the query of each tile as you put it on the Dom???
then you’d join on board, and assume your response would be an ordered vector that you treat as a 2d array represented in 1d.
the query language can give you a vector back…translating 1d -> 2d is trivial from there
of course. what i'm struggling with is how the board place view is connected to the place that it is viewing, but if I understand you well, having a view per place would not necessarily make sense. the thing is that i want to be able to detect clicks to places, which makes me think that a component instance for each of the places would make sense?
um, the vector response from your query would return maps. The maps themselves could contain the coords (what I’m calling tiles above).
hmm, my assertion error (conn? conn) is actually happening somewhere between merge-tree and merge-ref (when reading another key)
i can't get merge-ref to run to try and debug that
@danielstockton: probably because there are no refs in the response?
not really sure what refs means in this case
@hans: you would pass a callback INTO the tile component from board. Call that callback with the tile’s data
but if merge-ref is never called, it can't be what's messing things up
@danielstockton: sounds right to me 😄
ahaaaaaa
so merge-tree had to return @conn (de-refed atom)
not conn
seems like the internals are swapping the state
so i was swapping my atom for another atom
(what my atom was holding, that is)
is there supposed to be a transact! here: https://github.com/swannodette/om-next-demo/blob/master/todomvc/src/cljs/todomvc/core.cljs#L69
I think he mainly wrote it for a talk, and has not had time to flesh it out completely
very simplistic but also promising https://github.com/omcljs/om/blob/master/src/devcards/om/devcards/autocomplete.cljs
demonstrates many non-obvious things - how to conditionally remote, how to use core.async, how to use send etc.
the coolest part IMO is how dead simple the autocomplete ui is now that the asynchrony is removed
To anyone using my parsing helpers…quick note: I remembered during lucid dreaming last night that the AST has the type of the node…e.g. :join
. This means you can make read be almost totally automatic on the default db format by switching on type and just calling the join parsing helper.
See the sample version at:
https://github.com/awkay/om-tutorial/blob/c2c1a2637d1d47c7bbe23a2b32c6add07dc8610b/src/main/om_tutorial/local_read.cljs#L16
oh wait…type is :prop
…that’s unfortunate. OK, a little more work to detect the join, but hopefully you get the point.
was writing the code to test it out…also, if you’re doing a recursive query, the query from the parent’s ast sticks around unless you remember to clear it
Yeah, that collapses the entire read function for the Om default database format to about two lines of code unless you’re using unions or …
:om.query/root is probably more accurate to what it represents
and nothing else in there is namespaced…I’d actually vote the other way: :query-root
I was thinking it was in the state for a second, I'd agree with that.
So, I’ve been writing helper functions, like I mentioned above…I just tested out the generalized form, and it seems like it will work for reading the default database format (not supporting union yet). Also has support for decomplecting client-local data from stuff that came from a server by storing it in separate tables in app state, and “merging” them back in during query processing.
very alpha, but also stands to eliminate lots of code. Also has support for recursive queries with …
(including those that loop on themselves!)
(though the loop support isn’t really “true” loop support, it is depth limiting that you can specify)
I’m pretty happy with it so far. I was working on a SAX-style of local read that let you change read functions during recursion instead of multimethods (easier to trace), then the other stuff started falling out. I think I can make most of the common use-cases for local read automatic. I’m only using it with a very small toy app at the moment, but I’m not seeing big holes.
I’m probably more excited about the auto separation of client-local state…decomplects a whole mess of stuff:
you write a query like [:ui/checked :person/name]
and it scans for the UI bit in a top-level table.
@tony.kay: yeah, I definitely didn’t expect multimethods to be the only approach to parsing
in fact was somewhat concerned that the top level being implicit would create too many issues for alternative approaches
auto separation of client local / server sounds neat, but does your approach generalize to DataScript?
yeah, I know…but for those using the “default”, it would be nice not to have to write much of the read stuff.
This is what I have for a datascript parser
nice, thanks. If you have two clicks, look at this:
https://github.com/awkay/om-tutorial/blob/master/src/main/om_tutorial/local_read.cljs
Very short. Three different read implementations using the support functions. read-local
is hand-combined. generic-read-local
is one that should mostly work everywhere, and split-read-local
is like the first one, but split SAX style.
UI is in https://github.com/awkay/om-tutorial/blob/master/src/main/om_tutorial/ui.cljs, so you can see the queries
Hey, any clues as to how I’d get cljs.repl/source to work on cljs that has #js reader tags?
I traced it to that function, which traces down into the clj reader stuff, tried adding a js data reader to my clj runtime, but no luck
you might try it in your own devcard. Just use bhauman’s (dc/mkdn-pprint-source some-fn-var)
fixed up the AST bits some more, the AST is now walkable via :children
a la ClojureScript AST