Fork me on GitHub
#hoplon
<
2016-02-22
>
levitanong06:02:16

Hey @micha I’m thinking of changing if-tpl so that the conditional isn’t specified in :pred. So that where once the structure was:

(if-tpl :pred truth
  (true-tpl)
  (false-tpl))
It would now be
(if-tpl truth
  (true-tpl)
  (false-tpl)
What do you think?

thedavidmeister11:02:32

hey, so I just noticed that I can do (div :class “foo”) or (div { :class “foo” } ) equally well

thedavidmeister11:02:03

is that so I can pass hash maps to my custom elements and pass them through to the core elements?

thedavidmeister11:02:48

actually, I’ll just ask about what I’m looking at

thedavidmeister11:02:02

if i want to do defelem that just wants to set some values but passes the rest through, what should I do?

thedavidmeister11:02:53

e.g. (defelem html-range [{:keys [min max step]} opts] (input :type “range” :min min :max max :step step))

thedavidmeister12:02:00

so i could do that to get a little range slider, but then I don’t get to do things like :class any more

thedavidmeister12:02:17

really the only thing I want to set is :type “range”, everything else should just pass straight through

thedavidmeister12:02:26

what’s the best way to do that?

thedavidmeister12:02:42

and on an unrelated note, how is automated testing done for hoplon?

thedavidmeister12:02:05

and if it isn’t, would anybody be opposed to me writing tests using travis and https://github.com/semperos/clj-webdriver?

thedavidmeister12:02:30

@micha: I think i fixed a gnarly race condition (don’t even know what was causing or how to reliably reproduce) by making things “more abstract"

thedavidmeister12:02:34

good advice, i think

dm313:02:34

if defelem doesn't accept a map, you could always use something like mapply

dm313:02:01

(defelem html-range [opts _] (mapply input (assoc opts :type "range")))

dm313:02:07

and testing with webdriver is completely fine, although not sure how travis would matter here

thedavidmeister13:02:34

@dm3: well is there currently something running builds other than travis?

thedavidmeister13:02:56

@dm3 thanks for the mapply tip, i’ll try it out tomorrow simple_smile

dm313:02:44

I mean for testing that will match closest to the real thing Webdriver is best

dm313:02:58

how you run it is secondary

thedavidmeister13:02:45

i’ve tried circleci, it chokes on boot and runs out of memory

thedavidmeister13:02:31

i’ve used drone in the past, it wasn’t as flexible or integrated with other systems as travis

thedavidmeister13:02:46

alsooo, i already have travis working for a hoplon based project simple_smile

thedavidmeister13:02:30

so, i suggested it as I’ve already got some code snippets i can reuse

dm313:02:44

sure simple_smile whatever works

alandipert13:02:08

@thedavidmeister: you could do (defelem html-range [attrs opts] (input (assoc attrs :type "range")))

alandipert13:02:29

which leverages the fact that defelems happily accept a map as the first arg

thedavidmeister14:02:27

well, i suppose i’ll pick that up again tomorrow

dm314:02:12

I was wondering how to get around the lazy UI loading problem in a Hoplon way. I have a number of things in a list that have a Header and a Content. Headers get rendered all at once and content is fetched asynchronously. Each Item has a content-ref that gets resolved via an ajax call. It's kind of like how Castra mkremote works, only I have cells defined dynamically inside the element (as I understand mkremote only works for static state/`error`/`loading` cells). I was thinking of something like:

(let [content (cell= (content/resolve (:content-ref item)))]
  (div ...))
but this obviously doesn't work as resolve is asynchronous. I'd need resolve to either return a cell or accept a cell to set once the ajax call is complete. Seems like I'm missing something very basic here...

dm314:02:55

so I did the following:

(defn object-cell [object-id-cell]
  (with-let [result (cell (or (get @objects @object-id-cell) :in-progress))]
    (do-watch object-id-cell
              (fn [_ object-id]
                (if object-id
                  (get-object result object-id) ;this does AJAX if necessary
                  (reset! result :in-progress))))))
where objects is basically a cache

micha14:02:18

@dm3: so mkremote returns an rpc function, right?

micha14:02:27

and you call that function to make a rpc call

micha14:02:41

what that rpc function returns is a jquery promise

micha14:02:52

so suppose you have something like

micha14:02:08

(def doit (mkremote ...))

micha14:02:15

in your code you can do things like

micha14:02:54

(-> (doit arg arg) (.fail #(...)) (.done #(...)))

micha14:02:17

this is in addition to the global state, error, and loading cells

micha14:02:45

this is crucial for error handling, for example

dm314:02:46

so I'd do (cell= (-> (doit (:ref another-cell)) (.done #(...)))) ?

micha14:02:59

no, no cells there

micha14:02:20

although you will probably want to be swapping or resetting cells inside your fail/done/always callbacks

dm314:02:44

but if I need this to run when another-cell changes?

micha14:02:56

if you need what to run?

dm314:02:01

the doit

micha14:02:07

oh that's a different thing

micha14:02:29

(cell= (when other-cell (doit ...)))

micha14:02:42

or you can add a watch on another-cell

dm314:02:03

seems that's what I did in the above

dm314:02:19

just didn't understand the castra code properly

roti19:02:32

Hi, I am having some troubles getting an autocomplete functionality in a hoplon app

roti19:02:15

tried jqueryui autocomplete and selectize, but with not luck, I am suspecting I do something completely wrong

roti19:02:36

here's my code

roti19:02:51

(defmethod do! :selectize [elem _ opts] (.selectize (js/jQuery elem) (clj->js opts)))

roti19:02:28

(select :class "form-control" :id "doc-from-lang" :selectize {:options languages})

roti19:02:29

yeah, well that one uses a hoplon wrapper, which is on clojars, but vanished from github

roti19:02:46

I am thinking there is no big deal to use selectize directly

roti19:02:53

the thing is, my do! method gets called, and throws no error, but there is no effect visible

roti19:02:30

there must be something I am missing here...

micha19:02:16

i think your problem is that .selectize needs to be called after other things run

micha19:02:35

after the element is in the DOM already, for sure

micha19:02:54

you'll notice line 14 in the file i linked to

micha19:02:17

it's doing the .selectize asynchronously

micha19:02:29

after all the dom building is finished

micha19:02:43

which ensures that the element you're selectizing is in the dom when .selectize is called

micha19:02:58

that's why your thing isn't having any affect i think

micha19:02:09

you're calling selectize() before the element is in the dom

roti19:02:16

ok, let me try hoplon contrib then

roti19:02:39

I wasn't aware that hoplon contrib source was part of hoplon

roti19:02:53

the links from clojars are broken

alandipert20:02:15

unfortunately hoplon contrib is dead-ish

alandipert20:02:35

supplanted mostly by cljsjs, altho there were things it did that cljsjs doesn't, like auto css concatenation

roti20:02:03

ERROR: No such namespace: hoplon.jquery.selectize

roti20:02:25

that was [io.hoplon/jquery.selectize "0.1.2"]

roti20:02:14

ok, so can I use selectize like this?

roti20:02:14

(defmethod do! :selectize [elem _ opts] (with-init! (.selectize (js/jQuery elem) (clj->js opts))))

roti20:02:23

or do I need to defelem?

alandipert20:02:09

that should work

alandipert20:02:20

the defelem just has different affordances, like control over children... which maybe you don't need