Fork me on GitHub
#cljsrn
<
2015-11-11
>
johanatan02:11:35

hi, can anyone explain how to 'require' a node module within 'natal repl' ?

johanatan02:11:59

is it the same as for regular ClojureScript?

johanatan02:11:50

Last CLJS project I did used :cljsbuild and :node-dependencies keys in project.clj but it seems things work differently under Ambly/Natal

johanatan02:11:12

hmm, looks like js/require might be it

johanatan04:11:08

js/require does exist and has an effect when invoked but regardless of which module i try to require (and regardless if it's been installed via npm install --save) i get the red screen of death from React saying: "Requiring unknown module 'module-name'. If you are sure the module is there, try restarting the packager." This happens even for the 'react-native' module itself.

johanatan04:11:20

Any input/help on this would be greatly appreciated!

mfikes05:11:31

When using Ambly / Natal, your have a REPL directly into JavaScriptCore embedded in an iOS app. Since it isn’t Node.js, in order to consider how to use a Node module, you’d have to sort out whether that module’s code can be made to be loadable as a ClojureScript foreign lib, I suppose.

johanatan05:11:03

Oh, I had imagined that the React JS itself was also running in a JavaScriptCore. Are you suggesting that it is a different JavaScriptCore?

mfikes05:11:07

Yes, the React JS is in the JavaScriptCore instance inside the app

johanatan05:11:37

Then, the blessed React way to include node modules should also work for ClojureScript/Ambly no?

mfikes05:11:51

I have no experience using Node modules in React… maybe you could get something to properly load in if you mess with index.ios.js, but I don’t know. (I’m suggesting that you could start down the path of sorting out how to use a Node module with plain React Native…)

johanatan05:11:35

Yea, that is well documented. I will try poking around inside index.ios.js. Btw, does it make sense to delete the contents of the render in index.ios.js since we have one in core.cljs which will eventually get called?

mfikes05:11:47

(In that blog post it touches on similar stuff.)

johanatan05:11:39

So, I presume that if I create a 'var' holding the required module's exports in index.ios.js, it will be available to the rest of the ClojureScript code?

johanatan05:11:44

oh, what do you know, we already have a var React = require('react-native') in there. simple_smile

mfikes05:11:51

I haven’t tried completely removing the render in index.ios.js. Worth a try. I at least culled it down to being nothing more than returning <View/> in http://cljsrn.org/ambly.html

johanatan05:11:09

Ahh, i culled it down to return null and it works fine.

mfikes05:11:08

If you find improvements, Natal is still a work in progress (all of this stuff is), and perhaps contribute it with a PR simple_smile

johanatan05:11:20

Sure, will do

johanatan05:11:42

Hmm, unfortunately the React var created in index.ios.js is not available in ClojureScript/REPL

mfikes05:11:53

(It has been hacked together so that it minimally works, but there are tons of things to clean up. simple_smile )

mfikes05:11:59

There’s this (set! js/React (js/require "react-native/Libraries/react-native/react-native.js”)) at thein the awesome-project.core namespace

mfikes05:11:12

That’s probably what you are after

johanatan05:11:19

Ahh, yep. I bet that will work

johanatan05:11:55

It seems like the dependency was loaded but when I try to invoke anything from it, i get this:

testreact.core=> (.alert (.-AlertIOS js/React) "blah" "blahblah")
TypeError: undefined is not an object (evaluating 'React.AlertIOS')
	global code (NO_SOURCE_FILE)
testreact.core=> 

mfikes05:11:09

This works: (.alert js/React.AlertIOS "ba" "bah”)

johanatan05:11:14

Interesting. Any idea why it diverged from that awesome-proj way?

mfikes05:11:16

@johanatan: Your variant also works for me

johanatan05:11:24

Hmm, interesting. I'll try again

johanatan05:11:27

I just got yours to work

johanatan05:11:29

Ok, they both work for me too. Maybe it just needed a reboot

johanatan05:11:39

Ahh, I know what happened.

johanatan05:11:50

And it doesn't have the .js extension

mfikes05:11:20

Maybe that repo only works with an older React Native stack…

johanatan05:11:19

Ahh possibly

johanatan19:11:51

Is anyone using js/React.Image in an cljsrn project yet?

johanatan19:11:02

Looks like it requires a 'require' and that part is failing for me.

johanatan19:11:13

[React Native thinks I'm trying to load a module rather than an image]

johanatan19:11:32

{:source (js/require "image!intro-welcome")}

cldwalker19:11:03

I haven’t tried on latest (>= 0.14) but on earlier versions you can do [:image {:source “path/to.png” :static true}]

mfikes19:11:11

@johanatan: Yes. https://gist.github.com/mfikes/89c3e9a705a65e7ce1bb is the relevant bits from the image you can see in this demo https://youtu.be/Ci4uviG8S0o

johanatan19:11:02

I'm trying to load an image from my bundle though? Do I need to create a url for that?

mfikes19:11:17

Ahh.. dunno

johanatan19:11:57

the "image!filename" syntax doesn't seem to work

johanatan19:11:00

This will probably allow me to use the 'uri' path though: https://gist.github.com/icomkid/1004042

cldwalker19:11:05

@johanatan: That syntax won’t work for my suggestion but :source “filename” does work on earlier versions

johanatan19:11:45

does "filename" include any path info? I think React's packager flattens all of the resources to the root though no?

johanatan19:11:48

also, if it is an imageset do I need the ".imageset" extension?

johanatan19:11:59

Hmm, just tried with and without the extension and neither worked

johanatan19:11:46

Ahh, I remember seeing something about the names of the images inside the imageset must be particular for React to pick them up

johanatan19:11:22

@cldwalker: Did you ever see it work with an imageset?

cldwalker19:11:51

Yep. But we’re on 0.10. My syntax was off. It’s actually - :source {:isStatic true, :uri “MyIcon"}

johanatan19:11:14

That worked! Thx

wilkerlucio20:11:54

hi, can someone please help me with Ambly REPL setup on Cursive?

wilkerlucio20:11:01

when I run it though the Lein REPL I can't select the device

wilkerlucio20:11:21

running though clojure.main I get error while trying to load the repl:

wilkerlucio20:11:20

@mfikes: thanks, I did saw this link before, I'm trying to use the clojure.main approach but when I try to load the lib it can't find it, do you know what can I be doing wrong?

mfikes20:11:04

If you are using Lein, is ClojureScript and Ambly included as deps in project.clj?

wilkerlucio20:11:22

I'm following the tutorial from this page http://cljsrn.org/ambly.html

wilkerlucio20:11:43

trying to run with lein repl almost works, except there when I type the device number it just hangs

wilkerlucio20:11:23

here are the deps:

mfikes20:11:09

I don’t see Ambly in the classpath in that text snippet. Maybe you need to restart Cursive?

mfikes20:11:13

(Maybe Cursive is not picking up the changes to project.clj and it needs a restart.)

wilkerlucio20:11:57

@mfikes: right on the spot, restarting IntelliJ did the trick, thank you

johanatan21:11:01

Is it possible to use natal repl from Cursive?