Fork me on GitHub
#rum
<
2016-06-16
>
honzabrecka11:06:33

Anyone knows how to use with-ref with callback as described in https://facebook.github.io/react/docs/more-about-refs.html ?

niwinz11:06:09

@honzabrecka: just passing a callback to the with-ref second argument instead of a string?

niwinz11:06:11

it just uses react primitives for that

honzabrecka11:06:31

@niwinz: I know, but I need something like this: (with-ref [:audio [:source {:src “…"}]] #(…))

honzabrecka11:06:07

sablono/compile-html should be the answer

niwinz11:06:19

maybe something like:

niwinz11:06:53

(let [el (html [:audio [:source {:src "…"}]])]
  (with-ref el #(...)))

niwinz11:06:08

html is a macro that you should import from sablono

honzabrecka11:06:45

Great, thank you!

niwinz11:06:46

(:require [sablono.core :refer-macros [html]])

niwinz11:06:05

I'm not sure if it will work but seems like the way to go...

honzabrecka11:06:07

Works great 🙂

rauh12:06:46

@honzabrecka: you don't need with-ref here: You can just do [:audio {:ref #()} [:source....]]. Same btw, for :key.

rauh12:06:45

The with-{ref,key} is just when you get passed in the component as an argument and construct many of them, then you can change their key on-the-fly.

rauh12:06:36

They'd be called "higher order (react) components". Since they take a comp and return a comp. 🙂

kauko15:06:29

Hi! Can anyone help me with this? https://github.com/tonsky/rum/issues/75 🙂

niwinz15:06:29

@kauko: this does just that you want

kauko15:06:47

Hmm, really? 😄 I guess my brain kind of switches off when someone mentions lenses. Thank you, I'll have to look at this in more detail 🙂

niwinz15:06:13

do not be scared by the name, it is very simple, in fact...

niwinz15:06:30

@kauko: ^ a little example

niwinz15:06:25

is the same concept as reagent track...

niwinz15:06:30

but decoupled

kauko15:06:31

oh wow, that doesn't look hard at all 😄

kauko15:06:43

thank you! It's so much clearer now that I see it like that

kauko15:06:07

tbh the lentes docs weren't too good. I feel they have some weird grammar going on

niwinz15:06:12

lentes comes with a lot of predefined helpers that will make use it much simplier without need to define own lenses

niwinz15:06:37

@kauko: improvements are welcome, I'm not native english...

kauko15:06:14

ah shit, sorry 🙂 Didn't mean anything bad by it

niwinz15:06:20

so thinks like focusing on concrete key is as easy as (l/focus-atom (l/key :foobar) state)

niwinz15:06:32

without need to define own function

niwinz15:06:33

run/react expects an atom as argument and l/focus-atom just returns an atom that focus to a portion of other atom determined by lense 😉

niwinz15:06:39

And the main benefit of using it, surely in the same way as reagent does it, is that derived atom only make rerender the rum component when the focused state have changed.