Fork me on GitHub
#cljsrn
<
2019-03-29
>
souenzzo19:03:51

Not strictly related to #cljsn, but my app still feels like a website (aka do not work offline) On browsers, we solve it using web workers, but on react native there is no web workers. How should I handle it in react-native? AsyncStorage is the right way?

joshmiller20:03:21

As long as you don’t need to share data between apps (or with a share extension or similar), AsyncStorage is the way to go. Pretty easy key-value store that persists.

lepistane22:03:23

i have a question

lepistane22:03:40

is there a way to get html as a string in re-natal?

lepistane22:03:59

(js/fetch "") then what?

lepistane22:03:29

(.then #(str %) ?

jimberlage22:03:27

(.then (js/fetch "") #(.text resp))

jimberlage22:03:12

.text returns a promise, though, so watch out for that. https://developer.mozilla.org/en-US/docs/Web/API/Body/text

lepistane22:03:39

anyway i can resolve promise?

lepistane22:03:44

or wait for it?

jimberlage22:03:16

Unfortunately, not that I know of

lepistane22:03:02

(->
          (js/fetch "")
          (.then (fn [resp] (println (.text resp))))
          (.catch (fn [arg] (js/console.error arg))))

parens 4
👍 4
jimberlage22:03:31

You’d need to wait on the promise coming from .text, like

(-> (js/fetch "")
    (.then (fn [resp] (.text resp)))
    (.catch (fn [arg] (js/console.error arg)))
    (.then (fn [html-str] (println html-str))))

jimberlage22:03:57

But generally what you have is good

lepistane22:03:40

the problem i have is

lepistane22:03:49

i either get #object[Promise [object Object]] or [object Object]

lepistane22:03:55

for some reason i only get that for my project. i will investigate why

lepistane22:03:07

tnx for code

lepistane22:03:07

so this should do the trick?

jimberlage22:03:15

IO just doesn’t wait in JS. Or if you try to wait, you get a “A script on this page is unresponsive…” error or a frozen UI, depending on the environment you’re running in

lepistane23:03:10

i just tried to use re-find from repl but i wasn't able to. #object[TypeError TypeError: undefined is not an object (evaluating 'cljs.core.re_matcher.call')] was i wrong to think that clojure.core would be included/available in cljsrn?

lepistane23:03:16

i managed to use https://clojuredocs.org/clojure.core/subs... weird i might've been in weird repl state