Fork me on GitHub
#shadow-cljs
<
2021-07-24
>
sb07:07:55

Hello, if I would like to add for tailwind css a custom parameter, how can I do? `

[:span {:className (str "absolute top-0 right-0 block h-3 w-3 transform -translate-y-1/2 translate-x-1/2 rounded-full ring-2 ring-white" color)}]
Ofc I can a case around of span, but is here easier/nicer solution? (sorry if that is beginner question)

thheller07:07:54

I don't understand the question? Assuming color is just a regular string it should be detected as a tailwind class

sb11:07:14

Yes, that is regular and don’t detect.. eg color: “bg-teal-400”

sb11:07:41

Therefore I asked this…

sb11:07:35

Ok, in this need to work in this way as I thought.

thheller12:07:41

you need the whole string as described in the official docs https://tailwindcss.com/docs/optimizing-for-production#writing-purgeable-html

🙏 3
sb12:07:09

Yes, I solved in this way. So that is once way! Thanks the link!!

alexdavis18:07:25

I’m trying to use a js component, compiled from a local .jsx file to .js as specified https://shadow-cljs.github.io/docs/UsersGuide.html#_javascript_dialects, the only difference being I am using the react-native target. I get the following error when requiring my generated js file:

Uncaught Module not provided: shadow.js.shim.module$$babel$runtime$helpers$interopRequireDefault
Is this functionality just not supported in react native or do I need to do something different?

thheller18:07:42

should be supported but had issues some versions ago. which version do you use? also did you attempt to load the file over the REPL or was it part of the initial load?

thheller18:07:02

cannot load new npm dependencies over the REPL, need to be loaded by the app (rn metro) first

thheller18:07:43

namespaces starting with shadow.js.shim.module are the npm requires that are added

alexdavis18:07:39

Part of the initial load, using shadow 2.15.1

alexdavis18:07:54

It does occur to me though that I’m going from jsx to js to cljs to js again

alexdavis18:07:23

maybe there is a better way?

thheller18:07:32

don't know what you mean by that. don't know anything about what you are doing in general so only wild guesses here.

alexdavis18:07:22

I saw this when googling

thheller18:01:52
but you are using react-native anyways so you should figure out a way to let react-native compile the js files and not shadow-cljs
so thought maybe there was a way to skip the babel step

alexdavis18:07:29

but maybe I misunderstood

alexdavis18:07:48

I’ll try and make a minimal reproducible example

thheller19:07:52

the essence of "Module not provided" errors is that shadow-cljs generates a shadow$provide object entry to each npm dependency. under normal circumstances that is populated before the depdencny is actually accessed

thheller19:07:19

but if its not provided it was accessed before that

thheller19:07:43

which in react-native can happen if you do not reload the entire app and just load stuff over the REPL

thheller19:07:56

since in react-native metro needs to provide those deps and shadow-cljs can't

thheller19:07:06

and it can only provide them on the initial app load

thheller19:07:28

you can access JS dependencies directly using js/require but not via ns

thheller19:07:03

well technically you can also load them via the ns but then you'd need to make a node_modules package for those, which might be fine. don't know what kind of files you are trying to load

thheller19:07:42

ie. assuming you have :output-dir "app" you can (js/require "../js/some.jsx") to access the js file directly. again same limitations though, only on initial load

alexdavis19:07:29

I have a standard react app which imports the generated js files via ns like ["../gen/TaskList.js" :refer (TaskList)] , I’ve tried to replicate the same setup in my react native project but actually the generated file is different, even with exactly the same babel command and source file

alexdavis19:07:55

I’m fine with it being on inital load, I’m just trying to import some react components which are written in jsx

thheller19:07:24

why not generate them into a node_modules package and load via ["your-package/TaskList" :refer (TaskList)]"?

alexdavis19:07:38

Sure I’ll try that

alexdavis19:07:10

But the shadow guide does suggest the other approach (generate into src/gen and import that in ns )

thheller19:07:22

might even be possible to just ust jsx directly without the manual conversion, given thats its react-native

thheller19:07:02

react-native is sort of a special case because you have to deal with metro

alexdavis19:07:13

Yeah thats what I was thinking earlier, ok I’ll try that first, so make a package containing the jsx files and import it like any other npm module

alexdavis19:07:57

this is what babel generates btw, just incase there is a bug somewhere

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
    value: true
});
exports.TaskList = void 0;
var _react = _interopRequireDefault(require("react"));
var _reactNative = require("react-native");
var _this = this,
    _jsxFileName = "/src/stories/TaskList.tsx";
var TaskList = function TaskList() {
    return _react.default.createElement(_reactNative.View, {
        __self: _this,
        __source: {
            fileName: _jsxFileName,
            lineNumber: 6,
            columnNumber: 5
        }
    }, _react.default.createElement(_reactNative.Text, {
        __self: _this,
        __source: {
            fileName: _jsxFileName,
            lineNumber: 12,
            columnNumber: 7
        }
    }, "Hello, world!"));
};
exports.TaskList = TaskList;

alexdavis19:07:59

I definitely have @babel/runtime/helpers/interopRequireDefault in node_modules

alexdavis19:07:59

Ok I got it to work using (def TaskList (.-TaskList (js/require "../src/gen/TaskList.js"))) with the babel approach, still going to try the npm package way but that at least confirms theres nothing wrong with shadow

alexdavis19:07:12

Thanks for the help, I’m slowly learning how this stuff works…

thheller19:07:03

that can likely direclty load the jsx too

alexdavis19:07:36

Yep it can, nice

alexdavis19:07:50

Would that work in a standard react project?

alexdavis19:07:02

Or does it only work because of the metro bundler

alexdavis19:07:21

I guess the latter, because browsers can’t understand the jsx

thheller19:07:42

yeah, metro. basically you are using two separate bundlers

alexdavis19:07:44

Yeah, its got its downsides for sure but I guess not having another babel process is nice, probably will give nicer errors than doing the jsx -> js conversion pre cljs too