Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Idea: A fn like macro for defining HOF stateless component? #92

Closed
fonghou opened this issue Jul 26, 2016 · 5 comments
Closed

Idea: A fn like macro for defining HOF stateless component? #92

fonghou opened this issue Jul 26, 2016 · 5 comments

Comments

@fonghou
Copy link

fonghou commented Jul 26, 2016

Hello,

Would it be useful for a fn like macro, as to defc stateless component?

I'm thinking it'd be useful for higher-order function/component use cases. Essentially, what :wrap-render mixins do right now.

Thanks!

@tonsky
Copy link
Owner

tonsky commented Jul 27, 2016

Do you mean something beyond what defc can do right now? Can you give an
example use case?

On Tue, Jul 26, 2016, 21:34 Fong Hou [email protected] wrote:

Hello,

Would it be useful for a fn like macro, as to defc stateless component?

I'm thinking it'd be useful for higher-order function/component use cases.
Essentially, what :wrap-render mixins do right now.

Thanks!


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#92, or mute the thread
https://github.com/notifications/unsubscribe-auth/AARabK2zxZICFWV66ZLBaBv4ynsSrv2aks5qZhr9gaJpZM4JVNlM
.

@fonghou
Copy link
Author

fonghou commented Jul 27, 2016

Hi @tonsky,

I'm still exploring the idea, sorry can't show a good concrete example. Basically, renders that can be defined in (let [...]) form as lexical closures, rather than only top level vars by defc. This would create something I'd call dynamic configured stateless components, even allow them (I mean their definition, not args on invocation) observe parent owner's pre-render lifecycle events.

Right now, I copy this snippet to an utility function. It's fine for me just playing with the idea.

(defn render [render-fn]
  (let [class (fn [props]
                (apply render-fn (aget props ":rum/args")))
        _     (aset class "displayName" (.-name render-fn))
        ctor  (fn [& args]
                (js/React.createElement class #js { ":rum/args" args }))]
    (with-meta ctor { :rum/class class })))

Cheers!

@bendlas
Copy link

bendlas commented Aug 13, 2016

React (as of 14, i think) calls the following pattern stateless components:

(defn stateless-component [props]
  (html [:pre (pprint-str props)]))
;; ...
(js/React.createElement
 stateless-component
 #js{:title "Stateless" :other "Other"}
 "Foo" "Bar")

=>

<pre>#js {:title "Stateless", :other "Other", :children #js ["Foo" "Bar"]}</pre>

Sablono doesn't allow direct use of react components (see r0man/sablono#46), but we could consider supporting stateless components as outlined in the previous comment. The react team has been talking about adding optimiziations for stateless components, though I'm not sure whether they would beat rum/static.

@tonsky
Copy link
Owner

tonsky commented Aug 17, 2016

Stateless components are supported since 0.10.0. If you use no mixins, component will be compiled to single stateless function

@roman01la
Copy link
Collaborator

Closing this due to no activity. Also we don't want to do any fancy stuff with components definition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants