Fork me on GitHub
#cljsrn
<
2017-03-04
>
raspasov05:03:42

(set! js/window.FBSDK (js/require "react-native-fbsdk"))
(def ^js/window.FBSDK FBSDK js/window.FBSDK)
(def AccessToken (.-AccessToken FBSDK))

(-> AccessToken
    (.getCurrentAccessToken)
    (.then
      ;on success
      (fn [^js/Object success]
        (let [^js/Object access-token-obj (.. success -accessToken)
              fb-token (.toString access-token-obj)]
          (println "fb-token ::: " fb-token)))
      ;on error
      (fn [error])))

raspasov05:03:18

@rohit_ yes that always takes a while the first few times 🙂 (interop) - it does get easier though

Rohit Thadani07:03:26

why access it through js/window what magic is this :)

Rohit Thadani07:03:10

i'll try it and go figure this out too thanks @raspasov

Rohit Thadani07:03:05

what's the best resource to understand some of this interop

raspasov07:03:57

@rohit_ I think you can set it directly under js/FBSDK as well

raspasov07:03:29

and I think they are somehow the same thing 🙂 (I know nothing about JavaScript - j/k, kinda :D)

raspasov07:03:37

it does not make a difference for the interop

raspasov07:03:52

JavaScript - hack it till it works

Rohit Thadani07:03:44

i see all of the react-native examples so far seem to do the adapt-react-class and then access methods and properties on the object after i havent seen any places that access methods through like the global js/<object> and im having a hard time telling the difference

Rohit Thadani07:03:00

unless the best way is to just go read the source

raspasov07:03:14

what is adapt-react-class?

Rohit Thadani07:03:45

the re-natal template generates sample react native components that way

raspasov07:03:26

ah re-natal, thing, ok I’ll check it out

raspasov07:03:32

for React Native in many cases the best way to understand things is to read the source (which is actually very nicely structured and well commented in many cases)

raspasov07:03:59

in some cases the docs are wrong, and you have to figure out by the source

Rohit Thadani07:03:19

all the standard react components work that way but then there are 3rd party components not in the react library that are somehow different

raspasov07:03:36

wrong/outdated, like the prop used to be called this, but now it’s something else - it’s getting less and less but I’ve run into things around ScrollView

Rohit Thadani07:03:37

this sdk being one of them

Rohit Thadani07:03:13

the firebase api is similarly a little different too

raspasov07:03:43

just searched re-natal (I also use it)

raspasov07:03:48

adapt-react-class seems to be a reagent thing

raspasov07:03:36

not familiar with Reagent

Rohit Thadani07:03:37

i should go check the reagent source to see what it really is

Rohit Thadani07:03:53

i'll try what you gave me

raspasov07:03:20

tbh this seems kinda… weird, idk, but I have 0 experience with Reagent 🙂

raspasov07:03:32

have been doing React Native + om.next for ~9 months or so

Rohit Thadani07:03:48

i just started so i can use the help

raspasov07:03:51

it’s doing some deftype magic

Rohit Thadani07:03:23

but mostly stuckmyself into reframe and whatever renatal does by default

raspasov07:03:41

can’t help you with Reagent though 🙂 happy to help with pure React Native stuff or om.next/react native related

raspasov07:03:37

one thing I do like about om.next is the fact that all om-next components are effectively “pure” JavaScript react components

raspasov07:03:57

someone with Reagent experience should chime in here 🙂

Rohit Thadani07:03:14

probably i'll ask again if i cant get this to run

raspasov07:03:01

out of curiosity - are you just starting out with ClojureScript?

Rohit Thadani07:03:16

yes ive worked with clojure mostly before

Rohit Thadani07:03:23

all of this is new to me

raspasov07:03:31

and no React experience?

Rohit Thadani07:03:42

none other than toy example

raspasov07:03:43

JavaScript/Cljs doesn’t matter much

raspasov07:03:01

ok 🙂 good luck! should be fun, you’re in for a ride 🙂 (but it’s a good one)

raspasov07:03:35

I’ve built a 100% smooth production app in React Native + ClojureScript + om.next

Rohit Thadani07:03:43

when things work its awesome when they dont i have trouble figuring out why google wont help me :(

raspasov07:03:49

it’s great

raspasov07:03:00

oh yea Google ain’t much help here 🙂

raspasov07:03:17

you gotta go from, lack of a better cliche, “first principles” 😄

Rohit Thadani07:03:42

yes and that would be to go understand interop

raspasov07:03:07

uhm for regular js/cljs interop there will be SO answers I bet

Rohit Thadani07:03:20

i keep getting stuck there given i dont understand javacript well enough either

Rohit Thadani07:03:38

jsx is a mystery

raspasov07:03:52

it’s the React Native + cljs that’s mostly the uncharted path 🙂 but in the end, if you get a very good understanding of ClojureScript, it’s basically a 1:1 translation of js examples -> cljs

Rohit Thadani07:03:20

so all examples typed out in that form take time to translate

raspasov07:03:08

ok here’s a few things that might help (but might not be reagent specific)

raspasov07:03:42

(set! js/window.React (js/require "react"))
(set! js/window.ReactNative (js/require "react-native"))
(def ReactNative js/window.ReactNative)


(defn create-element [rn-component opts & children]
  (apply js/React.createElement rn-component (clj->js opts) children))

(def text (partial create-element (.-Text ReactNative)))

(text
  {:style {:color "white"  :letterSpacing 0.5 :fontWeight "200"}}
  "ClojureScript rocks!”)

raspasov07:03:58

a full example of how to require React, React Native, create a helper create-element function, define one of the React Native built-in components (Text) and then actually render the text (has to be inside a render method, of course)

raspasov07:03:21

ok gotta go, good luck! 🙂

Rohit Thadani07:03:28

thanks for the time

markel13:03:39

Hi guys! I'm pretty new to Clojure and Clojurescript, hoping to perform a switch from JS. Now it's time for me to try it out on a real project, so I've decided to take a shot with React Native and Re-Natal seems to be the best choice out there. Please cheer me up! 🙂 The Re-Natal channel is not so active as this one, so I guess I'll ask the question here, maybe someone can help... So here's the question. Re-Natal uses the 23 target android version by default, how to properly change it?

raspasov20:03:16

@markel good luck! 🙂 yes re-natal is a good choice

mozinator221:03:28

hey hey, anyone Berlin based ? giving a talk at the next clojure meetup about re-natal / reagent / re-frame / clojurescript