clojurescript

ClojureScript function prints strings, but will not return hiccup

心不动则不痛 提交于 2019-12-25 01:44:07
问题 I have a ClojureScript component: (defn main-panel [] (def nodes (-> @(re-frame/subscribe [::subs/nodes]))) (defn list-nodes [node] (prn (node :name))) (reagent/create-class {:component-did-mount (fn [] (api-service/get-file-tree)) :reagent-render (fn [] (doseq [node nodes] (if (= (node :depth) 0) (list-nodes node))))})) which prints strings to the console. But when I change the first function to: (defn list-nodes [node] [:<> [:h1 (node :name)]]) I don't get any html that is rendered - no

reagent/adapt-react-class fails with :optimizations :advanced

感情迁移 提交于 2019-12-25 01:36:33
问题 I'm importing a react component (using the :npm-deps support) and wrapping with the adapt-react-class adapter: (:require [reagent.core :as reagent] [react-helmet]) (def meta-tags* (reagent/adapt-react-class (aget react-helmet "default"))) (defn main-panel [] (let [] (fn [] [meta-tags*]))) This works fine for development, but when advanced compiler is on: Uncaught TypeError: Cannot call a class as a function Minimimal repo: https://github.com/fbielejec/npm-deps-demo 回答1: meta-tags* is a class,

How to figure out what protocols the type implements?

筅森魡賤 提交于 2019-12-24 12:44:16
问题 Given some type or record, how can I get all the protocols it implements? Let's say we have the following code: (defprotocol P1 (op1 [this])) (defprotocol P2 (op2 [this])) (defrecord R [] P1 (op1 [_] 1) P2 (op2 [_] 2)) And what I need is a function that does something like this: (all-protocols-for-type R) ;; => (P1 P2) It will be good if there's something backend-agnosting, because I'd like to have a mechanism for both Clojure and ClojureScript. UPD: the intention for this is to introspect

reagent component that orders spans by their computed sizes

风格不统一 提交于 2019-12-24 08:01:18
问题 I'm looking for a way to design a reagent component, which lists words sorted by their real(computed) widths, which they would have when rendered in the browser. (not the number of characters). The real width of an html element can be determined by the JavaScript method offsetWidth . However, it looks that in order to get a result, the element must be appended somewhere in the DOM. So this could be imperatively solved by creating a temporary, invisible container element appending some spans

Clojure + Clojurescript: Macro to read code of current file

吃可爱长大的小学妹 提交于 2019-12-24 05:57:50
问题 What I've Already Tried (defmacro magic [] (slurp *file*)) This works fine in clojure, but not in clojurescript (atleast not with lein figwheel). Original Question I need the following to work in both Clojure and Clojurescript. I think a macro is the right solution, but I'm open to other techniques. I want a way to read the current file as a string. For example, (ns my-test (:require blah)) (def foo 20) (println (blah/magic)) this should then result in (being printed out) (ns my-test (

Which changes to clojurescript atoms cause reagent components to re-render?

和自甴很熟 提交于 2019-12-24 05:46:14
问题 Consider the following reagent component. It uses a ref function, which updates a local state atom, based on the real size of a span element. This is done in order to re-render the component displaying its own size (defn show-my-size-comp [] (let [size (r/atom nil)] (fn [] (.log js/console "log!") [:div [:span {:ref (fn [el] (when el (reset! size (get-real-size el))))} "Hello, my size is:" ] [:span (prn-str @size)]]))) If the implementation of get-real-size returns a vector, the log message

Clojure Regex: If string is a URL, return string

浪子不回头ぞ 提交于 2019-12-24 04:42:10
问题 How can I return a valid URL given a string in Clojure. (re-matches #"????" "www.example.com")) (re-matches #"????" "http://example.com")) (re-matches #"????" "http://example.org")) // returns "http://example.org" (re-matches #"????" "htasdtp:/something")) // returns nil 回答1: Validating URL is not simple. Perhaps it's too complex to validate with regexp. Fortunately, there's a library called Apache Commons , which contains UrlValidator. Since Clojure can use Java library, you can use Apache

How to integrate libraries (clojars) into Lightable plugins

情到浓时终转凉″ 提交于 2019-12-24 04:26:28
问题 As exercise to gain experience with ClojureScript I am writing a LightTable Plugin and I find no way to successfully use any standard library, I read the official documentation and even updated it to reflect latest changes regarding paths etc.. I followed this video and read the whole thread on the google group trying the proposed solutions, even working with the latest github source without luck. I tried including core.async or cljs.http (I know the embedded nodejs alternative, just as

How to connect a ClojureScript node REPL to my :node-library shadow-cljs project?

眉间皱痕 提交于 2019-12-24 02:59:18
问题 Context I am building a Node.js library with ClojureScript and shadow-cljs. All development is done with ClojureScript but the build artefact is a NPM package. Example: (ns com.example.answer) (defn answer [] 42) build... release... then const answer = require('answer'); answer(); //=> 42 NB: I recently contributed the details of my build setup to this post. My entire development environment is in a Docker container and I am using the "Visual Studio Code Remote - Container" extension.

Multiple ClojureScript files on same page

て烟熏妆下的殇ゞ 提交于 2019-12-23 12:18:13
问题 I have a project that is using Jasmine to test the JavaScript. I am trying to switch to using ClojureScript for the front end. My project.clj is like (defproject myproject "0.1.0-SNAPSHOT" :dependencies [[org.clojure/clojure "1.5.1"] [org.clojure/clojurescript"0.0-1889"] [org.clojure/google-closure-library-third-party "0.0-2029"] [domina "1.0.0"] [hiccups "0.2.0"]] :plugins [[lein-cljsbuild "0.3.3"]] :cljsbuild { :builds [{ :source-paths ["src/clojurescript"] :compiler { :output-to "public