This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-04-01
Channels
- # aatree (3)
- # admin-announcements (2)
- # beginners (42)
- # boot (142)
- # cider (12)
- # cljsrn (11)
- # clojure (126)
- # clojure-greece (2)
- # clojure-poland (7)
- # clojure-russia (81)
- # clojure-uk (10)
- # clojurescript (81)
- # component (27)
- # core-typed (2)
- # cursive (18)
- # euroclojure (1)
- # gorilla (1)
- # hoplon (85)
- # immutant (2)
- # jobs (3)
- # leiningen (2)
- # off-topic (49)
- # om (151)
- # onyx (19)
- # parinfer (3)
- # re-frame (36)
- # reagent (2)
- # spacemacs (5)
- # untangled (32)
- # yada (9)
plaintext scrape of #C06DT2YSY https://gist.githubusercontent.com/selfsame/0174dc80e8e38fd221750e81a34b5bd9/raw/5fc72168ea82fbc773f7a7a46721de57e422076b/om.txt
Does anyone know why this would return an empty result?
om-tutorial.core=> (def app-state {:widget/people [[:people/by-id 1] [:people/by-id 2]],
:people/by-id
{1 {:db/id 1, :person/name "Sam", :person/mate [:people/by-id 2]},
2 {:db/id 2, :person/name "Jenny", :person/mate [:people/by-id 1]}}})
#'om-tutorial.core/app-state
om-tutorial.core=> (om/db->tree '[[:people/by-id 2]] app-state app-state)
{}
The strange thing is that on a different project, which has the /exact/ same dependencies, It returns this:
toy-calc.core=> (om/db->tree '[[:people/by-id 2]] app-state app-state)
{[:people/by-id 2] {:db/id 2, :person/name "Jenny", :person/mate [:people/by-id 1]}}
I'm on om 1.0.0-alpha31 for both projects. Does anyone have any ideas?Not answering your question, but I thought that db->tree
was recursive, so the result would not have any idents in it. However you get back the person's mate as an ident. Interesting thing is though, if db->tree
were to recurse with this data it would go on forever - because each person has the other as their mate.
For differences I would look at the component's ident methods - are they the same in both projects?
Yeah, no components for this. I'm grabbing the example from the "Using db->tree" section from here: https://awkay.github.io/om-tutorial/#!/om_tutorial.E_State_Reads_and_Parsing
Yeah I read the example once. Good to know that db->tree
doesn't need to know about ident
methods. I get fixated on them b/c important for normalization 😝
Yep, both snippets are copied and pasted from the repl that is started via rlwrap lein run -m clojure.main script/figwheel.clj
. Both were done on the same computer so the ~/.lein/profiles.clj
is the same and both have the exact same dependencies in the project.clj
.
Yep, I see lines like this in both projects:
Reading analysis cache for jar:file:/Users/bmaddy/.m2/repository/org/omcljs/om/1.0.0-alpha31/om-1.0.0-alpha31.jar!/om/core.cljs
I see those lines right after I run lein clean
. Is there another way I need to clean cljs stuff?
Still off topic a bit ☺️, but I see why it doesn't recurse forever now - because what is returned is determined by the query. At the end of the page you linked he gets the person's mate as well using [{[:people/by-id 1] [:person/name {:person/mate [:person/name]}]}]
.
figwheel wants you to put :clean-targets ^{:protect false} ["resources/public/js" ...]
in project.clj I think
I get the same result (even when also doing a lein clean
), but I'm still seeing the Reading analysis cache for
prefix on each line. I suspect that means it's still cached somewhere.
I would just rm -rf resources/public/js
if you didn't put anything non-generated in there
I'll look into the :clean-targets
thing and get that set up correctly. I've been scratching my head on this one for quite a while now--thanks so much for your help you guys! 😄
@bmaddy: the best way to get it done correctly is to move your compiled js stuffs (for dev and test) to public/resources/cljs, then you can specify the whole clean-targets to that folder.
Hi guys, I have problem regarding transacting in omnext.
the problem is:
I have a hook into html5 history popstate event. Regarding popstate event, whenever there is an event, it will make a transaction to change :navigation-point which would swap the main component of the app.
The problem is when I have a hook which is just printing stuffs out #(prn "stuff)
. The main component is swapped as expected.
But in my case, I have a hook that send a message to modal component through a channel to make it close any modals it has. In this case, the hook does work ( all modals are closed as expected ), but the main component is not changed even though there is a transaction that change :navigation-point
.
Do you guys have any idea what's wrong?
Without some code, it's pretty hard to guess what's wrong
@iwankaramazow: I will try to make a minimal gist. I have an idea for now, try to work on it then will get back soon.
If you want to give your RootComponent
some props when om/add-root!
-ing.
Should I go with local state?
Or can I somehow use a factory with add-root!
?
(om/add-root!
reconciler (rootview {:something "something-else"})
(gdom/getElement "app"))
@nxqd: I'll give it a run
@nxqd: I'm I right it's just set-state!
in initLocalState
?
Ah I see
regarding the problem I post above, I can see that if I try to do 2 or more actions that does mutate omnext at the same time, it only accepts one. But if I put a timeout between them, both are accepted. @anmonteiro maybe you have any idea regarding this.
@nxqd: you could try to combine the mutations into one mutation if they should happen at once (as a workaround)
@iwankaramazow: yes it would be the solution. But the thing is my 2 mutations are so separated. One modifies the internal state of a component, other is the same. And both are being triggered through a signal through channel.
@nxqd: maybe you can transduce the take on that channel, and transact the result?
Gotta love the daily issue grind
I want to pass some kind of config in a defui/ui
macro to configure some components when defining them.
Seems I can't get it to work with a simple function like:
(defn component-creator [config]
(ui
Object
(initLocalState [this]
(do stuff with config))
(render [this]
(div nil "Hello, world!"))))
Is it possible to do such a thing?Maybe in Reagent/reframe that would be possible. Not sure at all in Om Next. Can't you do something like send a function into the computed props of your component, or even different data. You can achieve all the variability you want with Om Next components I would have thought...
@cjmurphy: I'm refactoring my router into something more modular, the idea is to pass in the history from the top. I'll try to explore the computed-props path, but I'm not sure if that's something I want.
@iwankaramazow: you should read the post from anmonteiro regarding routing in om next
My router has been working since a few weeks, I'm trying to refactor everything
@iwankaramazow: you probably want to write a macro for the config thing
Not sure if a function will do it
@anmonteiro: Ah damnit, I have been putting of learning macros for a long time now 😄
Time to brew me some coffee & get it done
@nxqd: cant say nothing without a reproducible example
@iwankaramazow: it actually works with a function
(defn make-component [config]
(ui
Object
(initLocalState [_]
config)
(render [this]
(let [{:keys [a]} (om/get-state this)]
(dom/div nil (str "config: " a))))))
(defui Parent
Object
(render [this]
(dom/div nil
((om/factory (make-component {:a 2}))))))
I was curious so I tried it out
@anmonteiro: indeed, I think I can make it work with ui
Tried it before, but forgot to refer the macro in my namespace 😂
@a.espolov: Not yet. Use the todomvc project instead
how would you go about implementing something like https://github.com/FormidableLabs/radium in om?
for those of you that are unfamiliar, it allows you to write all your css using js and inline styles, but they still support psuedo selectors, media queries, and anything else native css does
apparently they wrap your components render function and add on-mouse-over, on-mouse-leave to check whether or not you are being hovered over
but how could you make a component accept another component and then add these sorts of methods into its children?
i think you would somehow have to scan all the children of your component, and look for anything that uses a {:style …}, then parse through that map and look for a key ‘hover’ so that way you know to add the event handlers into that component
@adamkowalski: not quite the same, but om-css let's you colocate styles in your components, and outputs a file with such styles in the end: https://github.com/ladderlife/om-css
interesting, nice work
but do the styles leak with that implementation? as in if I have two components which both use the same class names what happens then?
ohh nvm, I just read that you prefix the namespace/component name
@anmonteiro: so I read through the examples and it seems like you have most of the functionality of radium, but can you use a function to generate the style? An obviously contrived example would be a component whose color changes as a function of some integer. Maybe a task has no background color if there is still plenty of time to complete it, but as the deadline approaches it gains a red hue.
@adamkowalski: because we actually generate a CSS file that you need to include in your markup, styles are static
so that case would be handled by having 2 different classes, and applying the red-hue
class whenever time was almost over
right, I see what you are saying, and I get the benefits of static styles and having a css file. but for me I think there is a real tangible benefit to having dynamically generated styles. Like what if you wanted to transition from one thing to another. Or animation for example, rather than having to mess around with key frames, you could have a function which produces a different translation/rotation/scale/etc and easily make your animation stop whenever and go back to its original state if necessary
thats why I think the radium model is fascinating and I was always wondering if people are doing this in clojure or if there are any reasons that it is not popular
I currently have a mutation that sets a property in state, but doesn't need to cause a re-render
so when an element is hovered, the action checks to see if the dragging value is true
but I wanted to get it on the radar for history, even though it kind of doesn't matter
I just can't figure out why it's causing everything to re-render, even though nothing relies on it
there must be something about mutations that I don't understand, like if an element triggers a transaction, it is automatically re-rendered (and every item of it's kind)
the event comes from a tile, which is in a grid that contains hundreds of instances of a tile
I'm sorry this is not the case, the correct number of tiles re-render, but in my console I get
[66060.501s] [om.next] [object Object] query took 49.81999999843538 msecs
for each tile
How would you compose the IQuery of something like the Autocomplete widget (in the Remote Synchronization Tutorial) with a Root component? I understand that the Root component needs a union of all its component’s subqueries, but I can’t get it to work for parameterized subqueries. Example fragment below:
@uwo: query composition is right
but you need to pass the props down
in the read method of :component
, you can either use recursive parsing (to get the read method for :search/results
called)
or have the logic for :search/results
directly there and return it wrapped in {:search/results ...}
as the autocomplete widget will ultimately get nested more deeply in the application, would it make more sense to do the latter?
it makes sense to keep the read method for :search/results
because that's going to get called directly whenever set-query!
is called
because of full-query
@anmonteiro: thanks!
I’ve edited the file above to include a read method for the :component
key, and it’s now recursing into :search/results
. Excellent! Unfortunately the remote portion of the :search/results
read is no longer working. The remote was being fetched previously when Component was the target of add-root!
. Thoughts?
@uwo: nothing strange about either of those
1. if you're using recursive parsing, :remote
needs to be returned at top level
just like any recursive function
2. the read method is ran once for local targets (`target` = nil
) and once for every remote
so this top level read is not sufficient?
(defmethod read :component
[{:keys [query parser] :as env} k params]
{:value (parser env query)})
you're never returning :remote
in that read
all you ever return is :value
@uwo: my advice would not be to use recursive parsing, tbh
it's not needed there for sure
since it seems to be an autocompleter component, its read method will be called whenever there's a set-query!
call
yeah, I was wondering how I would know when to return remote, since that logic was already in the :search/restuls
read
on the first render (in which the :component
read method is called) you can just return whatever is in the state
or something like {:value {:search/results {}}}
it's important to return data matching the query, though
or Om won't know how to map data on subsequent renders (the call to set-query!
) to the autocompleter component
now that I’m doing
(defmethod read :component
[{:keys [query parser] :as env} k params]
{:value {:search/results []}})
I no longer see the :search/results
read fireright, that's expected
you don't see it in the first read
but as soon as you type something it should be called
@uwo: 1. which version of Om are you using? 2. what's (om/path this)
in your autocompleter component?
i don’t know if this is right, but it’s apparently fixed by doing:
(defui Root
static om/IQuery
(query [this]
[:comp]) ;removed (om/get-query Component)
...
you should be able to get it working with the previous query
I've written that in a project with a similar query
ok the path is correct then
yeah, with the the subquery removed from the Root it works just as it did when the Root had no IQuery implementation at all. Remote fetch occurs, but the data in the app state doesn’t immediately cause a rerender in the Component. Though this could be an unrelated bug (in my app)
@uwo: right but that'll cause you problems down the road
the query should compose to the root