Fork me on GitHub
#clojurescript
<
2017-10-13
>
cmal07:10:08

Hi! Is there a way to set some css psuedo classes(such as :before :after) selector in reagent node(.cljs file), in the :style property? just want the code to do dynamic calculations on those psuedo-classes by operating clojurescript.

cmal07:10:57

I found css hard to maintain if I do not write them in one place. There always are circumstances that I need to write css directly in clojurescript files, especially when I want the css change or calc dynamically. So I wonder whether I can write all my css directly in clojurescript?

lovuikeng07:10:03

@cmal you can do def in one place of the style fragments you need, true?

cmal08:10:06

@lovelykensho Sorry, I didn't quite catch you. Do you mean I should use def to do this?

cmal08:10:46

Just now I tried to search for an answer. It appears html cannot take inline pseudo-classes. So I should either write pseudo-classes in a css file or in the <style> tag. The css file way is not what I want, so I wonder is there a way to generate a <style> tag in the header.

thheller08:10:30

(defstyled page-title :h1
  [env]
  {:color "red"
   "&::before"
   {:content "- "}})

cmal08:10:35

@thheller BTW, Can style written by shadow.markup be compiled into the main.js file when using shadow-cljs?

thheller08:10:28

yes, thats the default.

cmal08:10:58

Wonderful!

lovuikeng08:10:46

man, that shadow makes a happy designer, thanks @thheller

mmer09:10:22

A real newbie question - what is the best set of opetions to use with Lein new to get a new clojurescript project. Somewhere I saw a video with someone creating a new project with a set + options that made sense, but I can't find the video segment now I need it.

thheller09:10:30

@mmer there are a couple templates for this, chestnut is a popular one https://github.com/plexus/chestnut

boogie66611:10:43

hello, does anybody know if clojurescript has specs for ns-form? (like clojure does in clojure.core.spec.alpha)

martinskou12:10:22

strings does not have the same interface in cljs and cls, is there a unified library one should use to avoid insanity?

mfikes13:10:06

@boogie666 ClojureScript proper doesn't yet have any such specs, but I believe the intent is to ultimately add them.

mfikes13:10:44

@martinskou Assuming you meant clj instead of cls, I'd recommend using the clojure.string namespace. Ignoring clojure.string/re-quote-replacement, the namespaces are practically identical between ClojureScript and Clojure and cover many use cases with string processing.

pesterhazy13:10:17

I'm running into this issue when writing a Chrome extension:

Unchecked runtime.lastError while running tabs.executeScript: Could not load file 'inject.js' for content script. It isn't UTF-8 encoded.

pesterhazy13:10:48

I think this is the offending line (as seen in less):

typeof a);}}};goog.json.Serializer.charToJsonCharCache_={'"':'\\"',"\\":"\\\\","/":"\\/","\b":"\\b","\f":"\\f","\n":"\\n","\r":"\\r","\t":"\\t","\x0B":"\\u000b"};goog.json.Serializer.charsToReplace_=/\uffff/.test("<U+FFFF>")?/[\\\"\x00-\x1f\x7f-\uffff]/g:/[\\\"\x00-\x1f\x7f-\xff]/g;

pesterhazy13:10:35

think the "<U+FFFF>" is the problem - this is google closure code I think

mfikes13:10:50

@pesterhazy This exact issue came up recently. We found that Closure indeed has the code in it, but IMHO, it is Chrome that is wrong.

pesterhazy13:10:15

@mfikes I found the discussion in the clojurians log

mfikes13:10:00

@pesterhazy Cool! You can see that we boiled it down to whether a certain pair of bytes is properly encoded or not.

pesterhazy13:10:31

I tried the suggested solution, :closure-output-charset "us-ascii" but that doesn't seem to have any affect

mfikes13:10:50

Actually, it is EF BF BF that is the byte sequence

pesterhazy13:10:26

hm I deleted the file and tried again - now "us-ascii" seems to work

pesterhazy13:10:48

@mfikes isutf8 from moreutils agrees with chrome that this is bogus utf8

mfikes13:10:50

(I think, to get to the bottom of this, we need to run Chrome, find the exact line of code in it, and file a bug with them.)

pesterhazy13:10:01

$ isutf8 chromex/inject.js
chromex/inject.js: line 2238, char 1, byte offset 217: invalid UTF-8 code

mfikes13:10:12

Ahh, interesting... hrm

pesterhazy13:10:23

maybe they share the same library (iconv?)

mfikes13:10:35

OK. So, it is pretty cut-n-dry: Is \uFFFF properly encoded or not via EF BF BF? http://www.fileformat.info/info/unicode/utf8.htm has a non-normative example (at the bottom) showing that. And I've seen other tools produce this sequence. I guess it is a matter of digging into the UTF-8 spec.

mfikes14:10:12

Looking at §3 of RFC 3629, you can see that the character 0000 FFFF would be encoded as the UTF-8 octet sequence 11101111 10111111 10111111, so I think Chrome is incorrect.

mfikes14:10:46

I suspect you can probably also reproduce it without using the offending Google Closure code by simply having a namespace with "\uFFFF" in it.

mfikes14:10:13

@pesterhazy I cannot repro with your minimal repro on my system

mfikes14:10:43

In fact, isutf8 on my system is fine with a file containing the bytes ef bf bf 0a

pesterhazy14:10:02

is it the isutf8 from moreutils? macos or linux?

pesterhazy14:10:25

$ isutf8 --help
Usage: /usr/local/Cellar/moreutils/0.57/libexec/bin/isutf8 [-hq] [--help] [--quiet] [file ...]
Check whether input files are valid UTF-8.
This is version 1.1.

mfikes14:10:56

macOS 10.13 High Sierra, with isutf8 installed via brew install moreutils

mfikes14:10:18

I have isutf8 version 1.2

pesterhazy14:10:31

could that be the difference?

pesterhazy14:10:05

I'm on 10.12.6

pesterhazy14:10:32

moreutils 0.60 released with these changes

New implementation of isutf8 by Julien Palard.
Noncharacters (ending with 0xFFFF and 0xFFFE) were considered invalid when encoded in utf8, according to the unicode standard they are valid: "However, they are not illegal in interchange, nor does their presence cause Unicode text to be ill-formed."
\xf4\xbf\xbf\xbf was considered valid UTF8, which is not: after 0xF4 the following byte should be between 80 and 8F.
This implementation does not try to decode the stream, so it checks it faster.
Add --list option. Closes: #691330

pesterhazy14:10:17

looks like this is a subtle topic 🙂

pesterhazy14:10:13

I've updated the repro-repo

mfikes14:10:57

@pesterhazy Yes, the relevant commit eliminated a bad test:

check 1 '\xef\xbf\xbf' # 0xFFFF
where the 1 here is the expected return code

p4ulcristian16:10:35

Hello guys, not totally off topic, but almost. I use reagent template, compojure, monger. It all works well, but now I have an interesting problem. I updated to Mac Os High Sierra.I compile with lein uberjar, put my app.jar on a digitalocean server. All things works well, but all REST calls happen in ISO-8859. I work for hungarian companies, so from "pöttyös bögre" it went to "p?tty?s b?gre". I went back to Mac Os Sierra and compiling works well again. But High Sierra seems to be more stable and fast, so does anyone know what can be the problem?

pesterhazy18:10:22

Any idea why this line

var temp__5276__auto__ = cljs.core.cst$kw$alt_DASH_impl.cljs$core$IFn$_invoke$arity$1(opts);
would throw with Cannot read property 'cljs$core$IFn$_invoke$arity$1' of undefined? The context is a simple (print "hello"). I'm writing a Chrome extension if that makes a difference.

dominicm18:10:43

What if cljs.core.cst?

Arno Rossouw18:10:00

Just out of curiosity , i see that some of ajax calls takes longer when the webservers under high load (cpu utilization). What are the probable causes?

pesterhazy18:10:15

@dominicm, I'm guessing cst$kw = constant keyword?

pesterhazy18:10:02

@dominicm, I think this just translates (:alt-impl opts)

pesterhazy18:10:30

so I guess the :alt-impl keyword hasn't been defined properly

dominicm18:10:46

That's very odd... where I think it's worth figuring out where that is supposed to happen

pesterhazy19:10:51

ok looks like lein clean resolved the issue

pesterhazy19:10:23

/me grumbles about caching

nek19:10:34

Is it supposed to not give a warning?

dnolen19:10:40

yes - there’s no warning at the moment for higher order operations with arithmetic fns

dnolen19:10:00

needs a lot more work for the higher order case

nek19:10:04

I see. Ok. Still millions time better than JS.

Arno Rossouw19:10:21

I'm interested in learning clojurescript, do you need to know javascript to be productive in clojurescript?

rgdelato19:10:53

mostly no, though knowing JS definitely helps, since CLJS doesn't tend to wrap things that are already fine (like js/parseInt)

rgdelato19:10:29

in a production app, you'll almost certainly need to interop with some JS libs, but if you're just trying to learn the language, YMMV

Arno Rossouw19:10:22

for example how would you code clojurescript with howler.js javascript library

sundarj19:10:00

using js interop

Arno Rossouw20:10:49

how would you create a countdown timer for 5 minutes that resets after 5 minutes?