Fork me on GitHub
#shadow-cljs
<
2020-02-11
>
Quest06:02:15

Anyone have a shadow-cljs react-native template without expo? I tried booting up https://github.com/fbielejec/shadow-cljs-react-native but on my Android VM it immediately gives the red React-Native error with Unknown at the top (from NativeRunnable.java, not very helpful)

thheller09:02:35

@quest not a template but this is the last example I made using only react-native https://github.com/thheller/reagent-react-native

Quest12:02:23

@thheller Thank you. I appreciate your uncanny ability to have an answer for everything. I bumped the react+native/reagent/shadow-cljs & added APK release instructions, opened PR https://github.com/thheller/reagent-react-native/pull/4

thheller12:02:03

@quest are you sure its safe to update the dependencies like that without touching the react-native dir (the generated files)?

Quest12:02:25

I assume they were regenerated after npm install, but I can't say for certain. The build still works after updates on my box

Quest12:02:00

if it's a straightforward safe path I could run the react-native init AwesomeProject and update the PR after I'm up tomorrow

thheller12:02:44

should be fine I guess. thx.

Quest12:02:48

Any time. I'm going to swap in re-frame into the template tomorrow, will release an example repo for that too.

Quest12:02:32

Little bit of context: I've been working on an app from the Expo re-frame template, but hit a point where I needed to access an Android API directly. You can do this with an ejected Expo app, but you lose many of the advantages of Expo.

Quest12:02:00

And your app exists in a sad intermediate "not react-native vanilla" and "not expo" state, so you lose all of the simplicity of Expo and accuracy of documentation for vanilla react-native.

Ivan Koz14:02:49

Got a json parse exception on run shadow.cljs.build-report app target/build-report.html Illegal character ((CTRL-CHAR, code 0)): only regular white space (\r, \n, \t) is allowed between tokens file: .shadow-cljs/builds/app-release-snapshot/release/shadow-js/module$node_modules$object_assign$index.js

Ivan Koz14:02:27

It was working fine before. Should i clean builds folder?

darwin14:02:09

look at node_modules/object_assign/index.js with hex editor, does it contain any zero bytes?

darwin14:02:26

the file could be corrupted for some reason

darwin14:02:04

e.g. (I can imagine) running npm install and some other tools stepping one each other toes when updating the files

Ivan Koz14:02:17

cleared the folder, works fine now

darwin14:02:07

there is probably something fishy in your setup which could cause clobbering those files

darwin14:02:15

(my wild guess)

Ivan Koz14:02:51

happened for the first time, so i have no idea

darwin14:02:35

didn’t you run any background process dealing with npm modules, e.g. npm install from terminal and concruently yarn install via IDE, or something like that

Ivan Koz14:02:03

i don't think so, but i had a blackout this morning, probably related

darwin14:02:25

could be a network error as well, and npm happily wrote incomplete file during update, hard to say

Ivan Koz14:02:45

cljsjs provide extern files for react, while shadow-cljs uses npm, should i do something extra for google closure to work properly?

darwin14:02:25

I use react direcly, without cljsjs, and it works out-of-the-box

Ivan Koz14:02:32

i dont quiet understand whats going on with shadow-cljs yet

Ivan Koz14:02:51

is it even normal to have 120+ kb of react, i've heard it's not very keen on dead code elimination

thheller14:02:20

npm code does not run through advanced compilation, so only very basic DCE is done

Ivan Koz14:02:57

how should i done it properly?

Ivan Koz14:02:16

say i wanna use rum and react

thheller14:02:40

not sure what you are asking? react-dom stays pretty much the same size it has on npm. so yes 120+kb is normal

Ivan Koz14:02:03

alright, i'm not sure what am i asking either

Ivan Koz14:02:25

it will get better with time, but for now i got a lot of blanks in my js knowledge

defa15:02:27

I was trying to get re-frisk-remote working for a react-native app that I build using a shadow-cljs with deps managed in a deps.edn file. Since there is no leiningen involved I’m not sure how to start the the web (i.e. lein re-frisk). So I guess I make my own ‘plugin’ for tools.deps to get an equivalent server running? Probably the wrong channel to ask, though.

p-himik16:02:57

I don't have any idea about react-native, but maybe re-frame-10x would work for you?

thheller16:02:40

I don't know what re-rrisk is or why it is a lein plugin in the first place sorry

defa19:02:35

It’s a debugging tool for re-frame based applications. re-frame is based around a single central app-db and re-frisk/re-frisk-remote can be used to trace and inspect the content of this db. The leinigen plugin spins up a web-server on the dev machine to provide the UI for traceing/inspecting the remote db. https://github.com/flexsurfer/re-frisk

defa19:02:55

Currently the inspect feature of shadow-cljs comes in handy and I can tap> re-frame’s app database. I will try to find some time to make the server component of re-frisk-remote standalone so I can use it with shadow-cljs and tools.deps.

ikitommi18:02:17

@mazin there is also https://gitlab.com/synqrinus/syn-antd, can just require the components what one needs.

mazin17:02:26

just now seeing this. thank you!

g7s20:02:23

Can i goog-define some constant in some namespace ns.a and use it in another ns.b? This doesn't seem to work if I require the ns.a from ns.b

thheller20:02:21

@g7s as far as CLJS in concerned (goog-define THING "foo") is the same as (def THING "foo"). so you'd refer to it like any other def using a/DEBUG (assuming (:require [ns.a :as a]))

g7s20:02:58

Then I must have done something weird.. I will check in the morning. Thanks!

Aleed20:02:01

is it possible to have shadow-cljs pickup a certain file based on its "extension"? i.e. in js you could configure webpack or metro to pick up .native or .web extensions or do you have to create completely different namespaces for each platform?

thheller20:02:50

no thats not supported. not sure why it should be though. what exactly do you want to do?

thheller20:02:18

I wrote about how I deal with platform specific code some time ago, maybe that helps https://gist.github.com/thheller/fa044450a6470fdd1afdbcf3f37a65e3 ?

Aleed20:02:56

i'm creating a single, cross platform app with react-native and react-native-web most of the code will be the same, but sometimes a certain file/feature will have to be different. so in js i could differentiate it simply by differretn file extensions, i.e. feature.web.js feature.ios.js and a single import statement into the app import feature from 'feature'

thheller21:02:22

yes but that would still be different files?

Aleed21:02:11

yeah, different files, but one import statement - so you can create a single app rather than a native app and a web app, with shared modules

thheller21:02:08

its not documented but shadow-cljs supports aliasing namespaces

👀 4
thheller21:02:54

so you can configure :build-options {:ns-aliases {some.app.feature some.app.feature-web}}

thheller21:02:18

so whenever anything tries to access some.app.feature it would end up using some.app.feature-web instead

thheller21:02:57

ie (:require [some.app.feature :as x]) would actually be (:require [some.app.feature-web :as x])

Aleed21:02:28

that will definitely work, thank you would it be possible to configure a convention globally?

thheller21:02:00

:build-defaults {:build-options ...} would apply it to all configured builds yes

Aleed21:02:01

in webpack for example, you have a list of extensions that are picked up, i.e., extensions: ['.web.js,' '.js']

thheller21:02:13

no thats not how that works

thheller21:02:22

they need to be actual normal namespaces

thheller21:02:36

so the code you'd write in (ns some.app.feature-web)

Aleed21:02:45

yeah, i understood your aliasing example

thheller21:02:47

there aren't two files pretending to be the same file

thheller21:02:08

and no, I do NOT recommend using this

thheller21:02:21

write proper software and use something like the gist I pasted before

thheller21:02:47

ns-aliasing should be the absolute last resort and pretty much only used if you don't have control over the code you need to alias

thheller21:02:39

writing interfaces with different implementations is a common software pattern. use it.

👍 4
Aleed21:02:34

thank you for recommendation, will read gist again and reconsider. but, from what I can tell, in both cases you're creating different implementations* based on same interface, it's just about the ease of being able to import them into single app (you let the bundler handle importing them based on some convention)

thheller21:02:52

yeah dunno I've never build a real react-native/web hybrid so no clue how well that actually works

royalaid23:02:40

@thheller So I just ran into a bit of footgun for the second time and I am not sure if shadow can help with this or what your advice is BUT here is the scenario: I am setting up segment to do tracking which requires you to use their analytics.js script from the window

royalaid23:02:00

so I have an object on the JS window that is called analytics

royalaid23:02:43

and then without putting it together until just now I had a namespace called analytics and then a file called segment so analytics.segment

royalaid23:02:24

this of course causes problems because shadow does exactly what you tell it and tries to make a analytics object but the two are basically in a race to get to the window spot first correct?

royalaid23:02:15

and the way that this manifested made me feel crazy because I kept calling functions that I knew were defined but which CLJS couldn't find because Segment's script had replaced my NS