GithubHelp home page GithubHelp logo

taoensso / tengen Goto Github PK

View Code? Open in Web Editor NEW
53.0 3.0 3.0 76 KB

Simple React component DSL for Clojure/Script

Home Page: https://www.taoensso.com/tengen

License: Eclipse Public License 1.0

Clojure 100.00%
clojure clojurescript epl taoensso reactjs react-native reagent om rum

tengen's People

Contributors

ptaoussanis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

tengen's Issues

Hook for linting support with clj-kondo

Not really an issue with your codebase, but I wanted to share my efforts to provide better linting support for the def-cmptfn macro.

Here is my hook for clj-kondo. It is not perfect (I just got started with the hooks API), but works fine for me. Maybe some users will find it helpful or can improve on it to provide more useful error messages.

(ns hooks.tengen
  (:require [clj-kondo.hooks-api :as api]))

(defn def-cmptfn
  [{:keys [:node]}]
  (let [[var-name-node & more] (rest (:children node))

        _ (when-not (api/token-node? var-name-node)
            (throw (ex-info "Missing function name!" {})))

        [docstring-node
         params-node & body] (if (api/string-node? (first more))
                               more
                               (cons nil more))

        _ (when-not (api/vector-node? params-node)
            (throw (ex-info "Missing function parameters!" {})))

        let-node (let [body-map (->> body
                                     (partition 2)
                                     (map (fn [[k v]] [(api/sexpr k) v]))
                                     (into {}))
                       _ (when-not (== (count body) (* (count body-map) 2))
                           (throw (ex-info "Missing key or value argument!" {})))
                       _ (when-not (every? keyword? (keys body-map))
                           (throw (ex-info "Arguments must be key-value pairs!" {})))

                       bindings (api/vector-node
                                  (concat 
                                    ;; bind “magic bindings” before others
                                    (mapv api/token-node
                                          ['this-mounting? nil
                                           'this-cmpt nil])
                                    (:children (:let-mount body-map))
                                    (:children (:let-render body-map))))
                       exprs (remove nil? 
                                     ;; to prevent “unused bindings” warning
                                     [(api/vector-node
                                        [(api/token-node 'this-mounting?)
                                         (api/token-node 'this-cmpt)])
                                      (:render body-map)
                                      (:post-render body-map)
                                      (:unmount body-map)])]
                   (api/list-node
                     (list* (api/token-node 'let)
                            bindings
                            exprs)))

        fn-node (api/list-node
                  (list (api/token-node 'fn)
                        params-node
                        let-node))

        new-node (api/list-node
                   (remove nil?
                           (list (api/token-node 'def)
                                 var-name-node
                                 docstring-node
                                 fn-node)))]
    {:node new-node}))

I put it in hooks/tengen.clj and wire it up in my config like this:

{...
 :hooks {:analyze-call {taoensso.tengen.reagent/def-cmptfn
                        hooks.tengen/def-cmptfn}}}

Implementation for Om

PRs welcome if someone familiar with Om feels like submitting?

Porting should be easy, just need a version of this function for Om. If someone can provide that function, I'll do the rest.

Cheers!

Implementation for Rum

PRs welcome if someone familiar with Rum feels like submitting?

Porting should be easy, just need a version of this function for Rum. If someone can provide that function, I'll do the rest.

Otherwise, please ping if there's demand and I'll try get around to this myself when I can :-)

Cheers!

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.