Fork me on GitHub
#reagent
<
2015-10-06
>
rohit16:10:33

I just ported over some react-motion demos over to reagent: https://ducky427.github.io/reagent-motion-demos

tel17:10:15

Anyone familiar with the reagent-render function?

tel17:10:26

I’d like to write a combinator which passes an argument to it

tel17:10:05

something like [(pass 1 my-component) 2 3] where (defn my-component [a b c] [:p (str a b c)])

tel17:10:15

and have it render to <p>1 2 3</p>

tel17:10:31

(obviously a static component isn’t what I’m going for simple_smile

tel17:10:08

perhaps it’s something like (defn pass [x f] (r/create-class {:reagent-render (fn [& args] (apply f x args))})?

tel17:10:56

The next step would be to get access to this in creating reagent-render

rohit17:10:14

@tel, i think something as simple as [(partial my-component 1) 2 3] should work

tel17:10:35

rohit ha, good point, but my example mislead

tel17:10:55

my real aim is to inject item from the context into a component

tel17:10:11

I can already do that by creating a new wrapper component

tel17:10:17

but I’d like to eliminate the wrappers

tel17:10:53

the above is cute but won’t work because it destroys the meta that might already be on the passed function

tel17:10:56

rather, misuses it

tel17:10:11

I guess I could just extract it

rohit17:10:40

@tel, hmmm. i think in :reagent-render calling (apply …) isn’t ideal

tel17:10:56

perf reasons?

rohit17:10:11

in the context of the wiki page, you are close to (…) form instead of […]

tel17:10:37

I’m confused

tel17:10:53

I understand the difference between the two uses

tel17:10:19

but how does that apply to apply?

rohit17:10:48

so in reagent-render you want to return a vector and not the result of a function call

tel17:10:53

pass constructs a component by design

tel17:10:51

what I ultimately want to do is to be able to write components like [:div [:p “foo bar”] [(with-ctx :kw f)]]

tel17:10:59

where f is a one-argument function

tel17:10:19

accepting a value returned from the :kw property in the react context

tel17:10:32

so my function doesn’t fiddle with rendering

tel17:10:39

it just modifies components

rohit17:10:17

i just misunderstood your initial example.

rohit17:10:54

i thought my-component is a reagent component. but you seem to suggest that its a closer to a function. [i hope i got it this time]

tel17:10:03

it could be a component

tel17:10:22

at the moment I’ve written it as though it’s a function intended to be interpreted as a component

tel17:10:34

but it could reasonably already be a component

tel17:10:46

so long as I can reach in and edit reagent-render still

tel17:10:54

is there perhaps a way to ensure that a given “component like” thing is forced to class map form?

tel17:10:10

that’s gotta be in the library somewhere

rohit17:10:42

a stupid question: could my-component be re-written as (defn my-component [a] (fn [b c] [:p (str a b c)]))

rohit17:10:02

and the call could be: [(my-component 1) 2 3]

tel17:10:16

rohit, could be, but the idea is to pull the a argument from the context

tel17:10:29

so while the example has it ambiently as 1

tel17:10:45

I’d really like to have access to r/current-component

rohit17:10:54

oh. got it.

tel17:10:45

huh, looks like the way the whole shebang works is that props is passed {:argv …} where argv are the arguments from the vector syntax

tel18:10:05

Is it possible to get access to this in component-will-mount?

tel18:10:11

you obviously can in react

tel18:10:26

but (this-as this (println this)) looks like it’s returning nil

tel18:10:33

actually js/window

tel18:10:40

it just gets passed in as an arg doesn’t it?

mikethompson21:10:32

@rohit those react-motion demos look good !