Fork me on GitHub
#hoplon
<
2015-09-03
>
onetom17:09:37

we often see this pattern, where we have some static and dynamic classes at the same time on a DOM element:

((div :class "some static classes")
 :class (cell= {:dynamic (...)})
 ...)

onetom17:09:16

is there a shorter way to do this?

onetom17:09:19

sometimes the order is important too, so ideally i would like to have something like... for example: :class (cell= [:some :static {:dynamic (condition)} :classes])

micha17:09:41

((div :class "some static classes") :class (cell= {:dynamic (...)}) ...)

micha17:09:51

interesting

micha17:09:57

you can make it!

onetom17:09:09

i know, i was just asking if there is something like this already

micha17:09:16

(defmethod do! :class* [elem k v] ...)

onetom17:09:19

also what u just said is exactly what i said, no?

micha17:09:43

sorry it was exactly the same simple_smile

micha17:09:54

you can even redefine :class

micha17:09:57

maybe like

onetom17:09:28

actually i dont even need the hash-map level...

micha17:09:38

(div :class (classes :foo :bar :baz (if ...)) ...)

onetom17:09:46

it can be a vector of classnames as keywords and bools

micha17:09:58

classes could be a macro that sees keywords and expressions and builds the cell=

micha17:09:30

like keyword followed by keyword is static

micha17:09:47

keyword followed by expression or symbol is dynamic

onetom17:09:47

was there any reason why only the 1st hash-map was interpreted as attributes?

onetom17:09:27

i was also thinking about intermixing inlined kw val pairs with hash-maps, since kids are either dom elements already or vectors or nil

micha17:09:31

that should be fixed with latest hoplon

onetom17:09:35

so they can be differentiated

micha17:09:58

i believe you can now put maps anywhere and they are merged

micha17:09:23

i mean for a little while now i think this has been the case

onetom17:09:41

ok, i will check it out

onetom17:09:18

why i was asking is because then the macro u mentioned can actually return a {:class (cell= ...)}

micha17:09:35

right, exactly

micha17:09:09

yeah i didn't think that far ahead, but it should work

onetom17:09:09

parse-args can then recognize ( (map | (kw val)) | (dom | vector | nil) )*

onetom17:09:13

anyway, i was just wondering as im merging our codebase

onetom17:09:12

i want to release the homepage with the latest hoplon rig, as a single page app, with backend connection, at least to staging tomorrow

onetom17:09:25

hmm... how am i supposed to use the current route-cell function? i got stuck at that implementation which had different implementations for different number of parameters

micha17:09:07

i thnk like (route-cell "default")

onetom17:09:08

should i do a (def route (route-cell)) to initialize routing and just compare that route cell afterwards?

micha17:09:22

there is an optional default route

micha17:09:27

but that's what i do

onetom17:09:28

i still need to retain the cell what it returns

micha17:09:36

yeah like you did

micha17:09:42

(def route (route-cell))

onetom17:09:57

it was actually quite nice in the past how it embedded the cell if u havent provided one from outside

micha17:09:00

i have some things that parse it into a map and make formula cells

onetom17:09:26

anyway, it's good enough like this

micha17:09:36

how do you mean embedded?

onetom17:09:10

it created a cell if u havent provided it as a parameter and every subsequent call was just returning that cell

onetom17:09:03

so u could use the (route-cell) to access the current route as well as to initialize the window.location.hash watching when it was called w params

micha18:09:20

(let [c (delay (route-cell))]
  (defn route-cell* [] @c))

onetom18:09:25

interesting... thx