clojurescript

ClojureScript, a dialect of Clojure that compiles to JavaScript http://clojurescript.org | Currently at 1.10.879
blmstrm 2020-11-14T05:24:13.202600Z

Hello! I wonder how I would go about rewriting the following (.decorate obj (fn [sel] (. (. sel enter) classed "ma" true))) with ..notation? I realise it should be something along the lines of (.decorate obj (fn [sel] (.. sel enter classed "ma" true))))but I canโ€™t figure out how I will get the ..notation to understand that "ma"and true are arguments to the classedfunction? Iโ€™m new to javascript so please excuse me if I mangle any terminology.

thheller 2020-11-14T09:27:13.205400Z

@blmstrm you "group" everything via () so (.. sel enter (classed "ma" true))

blmstrm 2020-11-14T10:27:26.205500Z

Ah, I didn't think about that! Thank you so much!

victorb 2020-11-14T11:07:09.207Z

Hello folks! Trying to wrangle self hosted clojurescript into doing what I want, and it kind of works but no macros seems to be available. Not sure if this is expected or not, any input? Current code in attached screenshot. For example, neither fn nor -> (and probably other) macros are not available and can't figure out how to get them in there, if even possible

borkdude 2020-11-14T12:19:20.207700Z

fwiw, I've got a self-hosted CLJS project here, maybe it's useful for debugging your problem: https://github.com/borkdude/re-find.web

thheller 2020-11-14T12:41:17.208Z

@victorbjelkholm429 in case you are trying this while compiling with shadow-cljs you kinda have to use the :bootstrap support described here https://code.thheller.com/blog/shadow-cljs/2017/10/14/bootstrap-support.html

thheller 2020-11-14T12:41:54.208300Z

otherwise self-hosted I believe relies on :dump-core true which isn't available in shadow-cljs

thheller 2020-11-14T12:42:29.208500Z

if you do this manually you must also properly load the macro code

thheller 2020-11-14T12:42:47.208700Z

not exactly sure how that would look when done the way you are doing it

victorb 2020-11-14T12:44:14.208900Z

Oh, I see, yeah I'm using shadow-cljs, I'll check out your link. Thanks @thheller and thanks for the example @borkdude, I'll check that out as well

borkdude 2020-11-14T13:42:09.209900Z

I have a .cljc file wherein I define a top level defn for CLJS only:

#(:cljs
  (defn buf [reader]
    (prn :frames (.-frames reader))
    (str (:buffer @(.-frames reader)))))
However, when I try to find/call this function, it is nil. Both in CLJS and self-hosted.
cljs.user=> edamame.impl.parser.parse_next
#object[edamame$impl$parser$parse_next]
cljs.user=> edamame.impl.parser.buf
nil
cljs.user=> (require '[edamame.impl.parser :as p] :reload-all)
nil
cljs.user=> (p/buf 1)
WARNING: Use of undeclared Var edamame.core/buf at line 1 <cljs repl>
wat?

victorb 2020-11-14T13:43:25.210100Z

Yup, the "bootstrap support" stuff did the trick, thanks again Thomas

borkdude 2020-11-14T13:47:07.210600Z

is this because defn is a macro? self-hosted should be able to handle this I think?

thheller 2020-11-14T14:47:36.211300Z

@borkdude when that is the actual code you are missing a #?( instead of #( ๐Ÿ˜‰

borkdude 2020-11-14T14:50:24.211500Z

yikes :) thanks

Erkan 2020-11-14T19:54:48.213900Z

Seems that I'm unable to run inline tests in a .cljs file. In a figwheel REPL I do

(cljs.test/run-tests 'my-namespace)
but it returns
Ran 0 tests containing 0 assertions.
0 failures, 0 errors.
is there any configuration that needs to be done in my project.clj file?

Erkan 2020-11-14T20:02:36.214Z

Yes it was, add

:test-paths    ["src"]
:)

jaime 2020-11-14T20:58:38.216900Z

Hi, is there a way for cljs to read a json file config? I'm trying to integrate this tool https://github.com/vadimdemedes/tailwind-rn But its generated config is in json file

import {create} from 'tailwind-rn';
import styles from './styles.json'; <----- importing json config

const {tailwind, getColor} = create(styles);

tailwind('text-blue-500 text-opacity-50');
Right now, I'm just thinking to copy the content of styles.json and declare a cljs map instead of importing the json file.

Dan Maltbie 2020-11-14T21:00:02.217600Z

I'm running into a problem when importing a javascript library that has a dependency on streaming_iterables.js. shadow-cljs compile reports successful compile but when I run my app I get the error below. I've simplified the the test to a simple app that works fine and then add the import of streaming_iterables.js where it fails. This may be related to Babel and support for async/await. I tried installing the regeneratorRuntime package with NPM but still fails. Any ideas why this is happening? Thanks for your help,Dan ========================= > web console output ReferenceError: regeneratorRuntime is not defined at Object.shadow$provide.module$node_modules$streaming_iterables$dist$index_mjs (index.mjs:44) at Object.shadow.js.jsRequire (js.js:66) at Object.shadow.js.require (js.js:113) at eval (./cljs-runtime/ttncore.main.js:2) at eval (<anonymous>) at Object.goog.globalEval (main.js:566) at Object.env.evalLoad (main.js:1659) at main.js:1966 env.evalLoad @ main.js:1662 (anonymous) @ main.js:1966

thheller 2020-11-14T21:04:56.218200Z

@dmaltbie should work if you add (:require ["regenerator-runtime/runtime"]) anytime before requiring the JS lib in question

thheller 2020-11-14T21:14:32.219200Z

@jaime.sangcap I'm guessing this is for react-native in which case you can just import the .json file as you would in JS as metro will be providing it anyways

thheller 2020-11-14T21:14:57.219400Z

well I guess it depends on the tool you are using but (js/require "../path/to/styles.json") should do it

Dan Maltbie 2020-11-14T21:20:13.219600Z

Thank you!!! That works. Thomas I am very impressed with the support you provide. A+

๐Ÿ‘ 1
jaime 2020-11-14T21:41:46.219900Z

I'm using krell and following this tutorial https://github.com/vouch-opensource/krell/wiki/Reagent-Tutorial I'm trying to log the import styles.json but it returns nil

(ns awesome-project.core
  (:require [reagent.core :as r]
            [reagent.react-native :as rn]))

(defn hello []
  [rn/view {:style {:flex 1 :align-items "center" :justify-content "center"}}
   [rn/text {:style {:font-size 50}} "Hello Krell!"]])

(defn ^:export -main [&amp; args]
  (r/as-element [hello]))


(comment
  (js/console.log (js/require "../../styles.json")))
Directory is
awesome-project/
--src/
----awesome-project/
------core.cljs
--styles.json

thheller 2020-11-14T21:43:01.220200Z

looks like you are trying to do this in the REPL which does not work

thheller 2020-11-14T21:43:14.220400Z

it needs to be in the code actually processed by metro

thheller 2020-11-14T21:43:54.220600Z

and it might need to be in the assets path. the js/require path needs to be relative to the path of the .js file you are loading. not relative to the .cljs file