This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-09-08
Channels
- # announcements (40)
- # babashka (14)
- # babashka-sci-dev (7)
- # beginners (50)
- # calva (8)
- # cider (25)
- # clj-kondo (7)
- # cljdoc (8)
- # cljs-dev (14)
- # clojars (6)
- # clojure (56)
- # clojure-australia (1)
- # clojure-berlin (2)
- # clojure-dev (16)
- # clojure-europe (18)
- # clojure-nl (1)
- # clojure-norway (5)
- # clojure-uk (7)
- # clojurescript (100)
- # cursive (57)
- # data-science (9)
- # datomic (6)
- # emacs (11)
- # figwheel (2)
- # fulcro (14)
- # helix (2)
- # hyperfiddle (9)
- # introduce-yourself (1)
- # lsp (20)
- # malli (14)
- # meander (34)
- # minecraft (1)
- # missionary (8)
- # off-topic (37)
- # pedestal (4)
- # polylith (18)
- # portal (3)
- # re-frame (5)
- # ring (33)
- # shadow-cljs (32)
- # spacemacs (6)
- # vim (16)
Hi, I am trying to implement promises using promesa. My requirement is to call the method which returns promise on button click event, but getting some errors (i.e 'Invalid expression [object Promise]'). The button onclick code is
(button/ui-button
{:appearance "primary"
:isDisabled (not enabled?)
:onClick
#(comp/transact!
this
[(save-config!)
(p/let [(send-event! :settings {:p1 "test"})])
(close-dialog!)]
{:optimistic? false})}
(tr "Save"))
The method is
(defn send-event! [settings]
(p/promise
(js/console.log
{:message "Settings data: "
:state settings})
(helper/sendEvent
constants/key
constants/event
(clj->js settings))))
So on button click event the promise needs to be resolved then close the window. Please suggest what I am missing. Your help is greatly appreciated. Thanksisn’t (p/let [(send-event! :settings {:p1 "test"})])
needs to have a binding var?
Though I added, same error
you're trying to comp a promise object
why not just use p/let instead of comp
We are using fulcro comp/transact to handle transaction processing.
It is existed code and needed. Can we invoke both on button click event?
i would probably wrap the whole thing in a plet
Hi all, does anyone have a suggestion for a directed graph library with toposort other than weavejester.dependency
? I'm having performance issues, toposort of50k dependencies (only integers) takes 800s
https://github.com/aysylu/loom has https://github.com/aysylu/loom/blob/d458f0c0dee9021983c64381b90a470f0178cc8e/src/loom/alg.cljc#L66
Interesting... wonder what the graph looks like in your case as I tried it with 30k of items where each child can have at most 2 parents, and on some real data it finished under a second or two.
there is also clojure.tools.namespace.dependency
, not sure about performance or if it works with integers, had only used it with symbols
https://gist.github.com/hiredman/075b45eaeb01e4b526ce6f8854685487#file-ur-component-clj-L1-L13 has my favorite toposort, but I've never used it on large inputs
when you checkout loom you might also look at https://github.com/Engelberg/ubergraph
weavejester.dependency is a fork of https://github.com/stuartsierra/dependency, the readme of which says "I originally developed this library to support namespace dependency tracking in https://github.com/clojure/tools.namespace, where it is still included under the name clojure.tools.namespace.dependency
."
what is the direction? does {0 #{1 3 2}}
mean 0 depends on 1 3 and 2, or that 1 3 and 2 depend on 0?
@U488CTM1V Ah, my bad with that performance comment - I misremembered. My experiments have initially started with weavejester/dependency
but I ended up using aysylu/loom
. No recollection of the reason for the switch though...
But thanks for the data, still curious to poke around.
@U0NCTKEV8, yeah 0 depends on 1 2 3
topological sort has linear time algorithms, so 800 sec sounds for an in-memory graph, even with 50k dependencies, sounds like they might not have implemented the linear time algorithm for topological sort.
There was a time years ago when the latest released version of tools.namespace implemented an algorithm that could be exponential time, depending upon the "shape" of the dependencies, and I submitted a PR (merged in years ago) that made it linear time.
yeah, and it would be possible that improvement didn't make it to the independent libraries
2022-09-08T18:28:12.993Z INFO [sacctsync.migrate.plan:109] - Building migration plan, this can take a very long time
2022-09-08T18:28:15.602Z DEBUG [sacctsync.migrate.plan:91] - Dependency graphs built in 00:02.608
2022-09-08T18:28:16.035Z DEBUG [sacctsync.migrate.plan:105] - Topo-sort lists built in 0.424180627
2022-09-08T18:28:16.425Z DEBUG [sacctsync.migrate.plan:82] - Plan actions built in 0.389160914
2022-09-08T18:28:16.426Z INFO [sacctsync.migrate.plan:114] - Building migration plan complete: 3.43s
Nice, I guess you can remove this can take a very long time
Is there a sorted-map/sorted-set implementation that supports iterating over the keys in order with a seek operation. So something like
(defprotocol SortedIterator
(first [this])
(next [this])
(seek [this k]))
where first
and next
have the usual meanings and seek
skips to the next key that is at least k
. The guarantees should be that next
and seek
take at most O(log N) and that if there are m
keys visited in ascending order that it should be amortized O(1 + log(N/m)). I looked at https://github.com/clojure/data.avl but that doesn't seem to give me the amortized guarantee.the new IDrop stuff in 1.12.0-alpha1 could be used to make (drop n) do what you're calling seek (so reuses an existing clojure api)
if something like persistent-sorted-sort or any other such data structure wanted to implement it (we did not do that for the built-in sorted set/map)
@U0NCTKEV8 With that implementation I also run into the issue that once I have sliced, I can't slice again.
if you are fine with mutability, https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ConcurrentSkipListSet.html allows for slicing into subsets
@U064X3EF3 Interesting. So you one could potentially add that new interface here https://github.com/clojure/data.avl/blob/master/src/main/clojure/clojure/data/avl.clj#L1203 ?
it will give a O(log N) guarantee, but it won't give me the amortized guarantee of O(1) if I want to visit every key in order.
sorted maps/sets implement a function called seqFrom that takes a starting key https://github.com/clojure/clojure/blob/5ffe3833508495ca7c635d47ad7a1c8b820eab76/src/jvm/clojure/lang/Sorted.java#L24
Yes I am aware of subseq
, but I won't be able to call subseq
again on the resulting seq
.
if I want to use core types in a protocol what should I use for vectors and hashmaps and sets?
clojure.lang.IPersistentMap and clojure.lang.IPersistentVector and clojure.lang.IPersistentSet?
yes, those are the best interfaces denoting the persistent data structures (but as they are not types you control, be somewhat careful)
thanks!