hoplon / hoplon

Simple and powerful tool for building web apps out of highly composable elements in ClojureScript.
https://hoplon.io/
Eclipse Public License 1.0
1.02k stars 65 forks source link

interpolate links? #46

Closed johnjelinek closed 10 years ago

johnjelinek commented 10 years ago
(audio :controls "controls"
           (source :src (text "~{rpc/get-song}") :type "audio/mpeg")
           (text "Your browser does not support the audio element."))

yields

<audio controls="controls">
  <source src="[object Text]" type="audio/mpeg">
  Your browser does not support the audio element.
</audio>

How can I get this value into the src property?

alandipert commented 10 years ago

Hi John,

There isn't an explicit implementation of the do! multimethod in Hoplon for the src attribute currently. However, there is an :attr method you could use like this:

(source :attr (cell= {"src" rpc/get-song}))

Alternatively, you could implement a do! method for handling :src yourself. However, I think this would be a handy addition to Hoplon. It's kind of weird we don't have it already :-)

@micha what do you think?

johnjelinek commented 10 years ago
(source :attr (cell= {"src" rpc/get-song}))

worked :)

Do you want me to close this or should it remain open until you hear back from @micha regarding a do!?

micha commented 10 years ago

Hi! You could also do this, if you prefer:

(source :src rpc/get-song)
alandipert commented 10 years ago

D'oh! What I said about :src currently going unhandled by do! is wrong - :src falls through to ::default which defers to the :attr implementation.

The reason your original code didn't work is because text returns an HTML TextNode with a reactive text content, not a cell. Since the TextNode isn't a cell, str is called on it to obtain "[object Text]" instead of :src being wired reactively.

Please close this if this makes sense and you accept my apology for confusing the issue :smile:

johnjelinek commented 10 years ago

cool, thanks for the update!