Fork me on GitHub
#clojurescript
<
2017-12-24
>
Miloslav12:12:06

could you please say once and forever HOW DO I IMPORT?

Miloslav12:12:33

(ns frontend-boilerplate.db
  (:require [re-frame.core :as re-frame]
  			[goog.crypt :as crypt])) 

(.log js/console crypt) ;undeclared variable

Miloslav12:12:51

why i'm still getting that warning?

Miloslav12:12:10

and

(.log js/console goog.crypt)
works just fine

Miloslav12:12:45

i just don't get it

rauh12:12:25

@melvoloskov That code also wouldn't work with clojure or requiring cljs namespaces. The crypt is just an alias. If you refer to something within the namespace it'll be properly resolved

Miloslav12:12:10

and how do I do it the right way?

Miloslav12:12:55

why [re-frame.core :as re-frame] works and I just can use re-frame, and then exactly the same [goog.crypt :as crypt] doesn't?

rauh12:12:05

Require is all good in your case. Nothing wrong with it. Just call a fn like crypt/utf8ByteArrayToString

rauh12:12:02

@melvoloskov You'll get the same error when you use re-frame by itself.

Miloslav12:12:47

thank you! thanks a lot! that was the answer I was looking for all that time I spend trying to figure that out

celwell18:12:13

Hi, I added the dependency [cljsjs/react-color "2.13.1-0"] to the 'simple' re-frame example, and now it won't load. Using figwheel, getting console error: "Uncaught TypeError: getNextDebugID is not a function". When I remove it again, it loads normally.

juhoteperi20:12:23

@celwell Check lein deps :tree and look which React version is getting used, should be 15.6 but old cljsjs lib might bring in 15.4

ErhardtMundt22:12:18

I just came to know there's no such <!! in clojurescript

ErhardtMundt22:12:26

what's the alternative?

qqq22:12:21

cljs is single threaded because js is single threaded

ErhardtMundt22:12:02

@qqq so how should I deal with channels outside a go block?

noisesmith22:12:13

put! and take! still work iirc

noisesmith22:12:24

but usually the option is to use them inside a go block

noisesmith22:12:57

one thing that can help is having take! with a callback that modifies an atom you use elsewhere (or altering that atom inside a go block)

ErhardtMundt22:12:59

mmh, well I use cljs-http to make some http request

ErhardtMundt22:12:22

I still have to figure out how to use the channel I get from the request

noisesmith22:12:58

you can alter some data inside a go block, or you can put the rest of your code in go blocks after that point, or you can use take! and do your side effect in a callback

ErhardtMundt22:12:38

I'm using re-frame and I have the http request being done from the block of an event handler

ErhardtMundt22:12:01

event handlers should return the new state of the app

ErhardtMundt22:12:20

so I need to have the results available synchronously

noisesmith22:12:18

then you shouldn't be using an async library?

noisesmith22:12:50

can't you create a new event in the callback of a take! call?

ErhardtMundt22:12:22

that's a viable solution

ErhardtMundt22:12:29

but still I wonder if there's anything similar to await/`async` in clojurescript

noisesmith22:12:29

core.async is highly opinionated, and make a number of actions impossible that usually one would consider to be normal

noisesmith22:12:46

it uses a formal model called CSP and adding certain operations to CSP breaks it

noisesmith22:12:29

I'd assume it's possible to use await / async, I'm not sure what that looks like though

manutter5123:12:33

@erhardt.mundt You should look at re-frame/http-fx (https://github.com/Day8/re-frame-http-fx) to do http calls asynchronously

manutter5123:12:36

There's no need to wait for a response to an http request. You have one handler make the call, and then when the response comes in, you fire a new event to handle it.