Giter Club home page Giter Club logo

Comments (5)

tonsky avatar tonsky commented on July 19, 2024

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
.

from rum.

fonghou avatar fonghou commented on July 19, 2024

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!

from rum.

bendlas avatar bendlas commented on July 19, 2024

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.

from rum.

tonsky avatar tonsky commented on July 19, 2024

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

from rum.

roman01la avatar roman01la commented on July 19, 2024

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

from rum.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.