Where is the best place to set NODE_ENV? Do I just put a line of (set! js/NODE_ENV (if goog.DEBUG "development" "production")
in my entry point? Is there a way to say this in the shadow-cljs.edn?
hi, can we make this work somehow with shadow https://www.npmjs.com/package/babel-plugin-assign-directive ?
seems like there is a NOTE saying no š
yes , thats why im here š
why the link is 404 from the package site?
can't even read the source
idk its outdated, its possible to add directive with a macro , im more interesting in how we can use babel plugin for generated js code with shadow
or probably it could be not a bubel plugin, i mean we need access to js code to be able to change it in runtime
I am not sure I fully understand. If I generate my js code with shadow-cljs, why would I take the output of that and try using another approach to modify it? Why not just modify at the beginning
I know lots of tooling on how to modify js code from js, but that is in js land entirely
we need to get this
user.i_use_worklet*=*function(){varĀ _f*=*functionĀ _f(){*return*Ā console.log("HeyĀ I'mĀ runningĀ onĀ theĀ UIĀ thread");};_f._closure*=*{console*:*console};_f.asString*=*"function(){const{console}=this._closure;{returnĀ console.log(\"HeyĀ I'mĀ runningĀ onĀ theĀ UIĀ thread\");}}";global.__reanimatedWorkletInit(_f);*return*Ā _f;}();
from this
user.i_use_worklet*=*function(){"worklet";*return*Ā console.log("HeyĀ I'mĀ runningĀ onĀ theĀ UIĀ thread");};
hm actually, probably we need this only in the release build
I know I would write something custom with this https://www.npmjs.com/package/falafelhttps://www.npmjs.com/package/falafel š
@andre I don't know how this works at all but maybe you want to write the worklet code directly in JS and just use it from CLJS? or do you really need to write those in CLJS?
its an env variable so you NEVER set it in your code
so my idea is to run re-frame event handlers in a separate thread, so yeah it should be cljs code
but for my idea i don't need it in develop, only in production for performance reasons
the main issue is that :advanced
will likely remove the "worklet;"
thing
yeah, i also thought about this
it'll also agressively inline functions and so on so the code is never what you wrote after :advanced
yeah thats true
also I don't have a clue how worklets actually work but I'd assume it would require a lot of serialization
if it all runs in a separate thread and you can't share memory in JS
so running re-frame event handlers seems like an absolute no go for me? too much overhead serializing the app-db back and forth?
> When you pass arguments, they will be copied to the UI JS context.
seems like that š
https://www.npmjs.com/package/babel-plugin-assign-directive the github repo for this doesn't exist anymore so I think this never actually worked? can't see how this would work with any other CLJS tool either as :advanced
or even :simple
would be the major hurdle here
so the only way I see this working is with actual JS functions just called from CLJS but not passing through CLJS tooling, just metro
yeah, thanks
a custom worklet-fn special form could be created to create the code you need but yeah its applications are very limited and I don't expect this to ever work for functions using CLJS datastructures anywhere. basic JS types maybe work though.
how should those warnings be fixed for shadow?
Note that the code does work, also under advanced
@borkdude first of all this has nothing to do with shadow-cljs, you'd get those warning for regular CLJS as well if you were to enable them. so the only difference is that shadow-cljs defaults to having them enabled automatically vs. manually. You can either use (set! *warn-on-infer* false)
somewhere above those forms if you know they are safe and can be renamed (which they likely can)
@thheller Adding an extra local type hint solved the warnings. I don't understand why because that type hint was already on the return tag of the function. But thanks. It was reported by a shadow-cljs users, I have never seen this warning before.
unsure why the return type hint is missing though. that should be ok
I will check out warn-on-infer, it sounds useful
yeah if you set that to true you should get the warnings with the regular cljs compiler too
basically shadow-cljs just sets that to true by default for local files (ie. files not in .jar)
I do remember some weird issue with return type hints but not sure. I think in some places it was a little inconsistent and (defn ^Return foo [] ...)
worked but (defn foo ^Return [] ...)
didn't
or the other way. you really don't see them used all that often :P
Hello. I have another question, probably quite stupid again, but I'm banging my head against this for a few hours. I'm trying to adapt this example: https://github.com/reactchartjs/react-chartjs-2/blob/master/example/src/charts/Line.js
(ns my-app.views
(:require ["react-chartjs-2" :refer [Line]]))
(defn chart []
[:> Line
{:data {:labels ["1" "2" "3" "4" "5" "6"]
:datasets [{:label "# of Votes"
:data [12 19 3 5 2 3]
:fill false
:backgroundColor "rgb(255, 99, 132)"
:borderColor "rgba(255, 99, 132, 0.2)"}]}
:options {:scales {:yAxes [{:ticks {:beginAtZero true}}]}}}])
But I get this error:
error when calling lifecycle function my-app.core/mount-root Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports. Check the render method of `my-app.views.chart`.
Line
seems to be undefined and I don't know why. Both "chart.js": "^3.1.1"
and "react-chartjs-2": "^3.0.2"
are in my package.json. I'm quite sure it was working yesterday, but don't know what I've changedSo what is Line?
oh, i can't read, sorry, you said it's undefined
It should be a react component, provided by react-chartjs-2
hehe
can you check how that component exports? sometimes people do weird things
although if it was working and you didn't update anything then it's probably not that
I've added nouislider-react
to the project, but I just removed it and it's still not working. What should I look for in the exports? I'm not too familiar with JS modules and exports, but I found this in node_modules/react-chartjs-2/dist/index.js
:
var Line = React.forwardRef(function (props, ref) {
return React__default.createElement(ChartComponent, Object.assign({}, props, {
type: 'line',
ref: ref,
options: props.options || {}
}));
});
there should be either export or module exports
but I don't think that's the issue if it was working, more likely a typo or similar issue
I guess it was a caching issue. I deleted everything and restored it from git and restarted shadow-cljs. Now it's working. Thank you anyway!
I thought I tried that before, but this time I removed not just the node modules, but everything
glad it's working š