This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-02-15
Channels
- # announcements (27)
- # architecture (15)
- # aws (2)
- # babashka (5)
- # beginners (77)
- # calva (42)
- # cider (22)
- # clj-kondo (47)
- # cljfx (7)
- # clojure (66)
- # clojure-australia (1)
- # clojure-europe (32)
- # clojure-france (10)
- # clojure-israel (2)
- # clojure-italy (1)
- # clojure-nl (8)
- # clojure-uk (53)
- # clojurescript (29)
- # conjure (28)
- # core-async (2)
- # cursive (26)
- # data-science (1)
- # datascript (11)
- # datomic (33)
- # emacs (4)
- # fulcro (5)
- # girouette (3)
- # helix (1)
- # jobs (2)
- # leiningen (17)
- # luminus (2)
- # malli (15)
- # music (2)
- # off-topic (51)
- # pathom (3)
- # rdf (91)
- # remote-jobs (1)
- # reveal (7)
- # sci (6)
- # shadow-cljs (10)
- # spacemacs (3)
- # sql (23)
- # tools-deps (52)
- # uncomplicate (2)
- # vim (3)
- # xtdb (9)
Can Closure figure out that type extensions are never used and remove related code? (eg. using extend-type
with a protocol in a library but the user ends up not using that).
I would say no based on what I see but who knows
yes in theory. in practice unlikely though. CLJS isn't "typed" enough for this to work reliably
And I guess there is no way to help the process? Some type annotation somewhere?
depends. can't explain the process really. yes, typehints and eliminating dynamic uses of the protocol
basically you'll have to spend a bunch of time going through pseudo-named code looking for reasons why the code stays alive when you think it should be removed
closure is surprisingly good but many of the more advanced features really only work in fully typed code
So essentially, when extending protocols, dead code is rather to be expected on native types and custom ones that are used at least once somewhere
Makes one slightly paranoid about overusing protocols
well you are using protocols with the intent of using them no? I mean you don't intend to write dead code from the start?
In the context of an app yes indeed, in the context of a lib it's best to think twice and try no to be too clever
This is a good way to do it: https://github.com/andrewmcveigh/cljs-time/blob/master/src/cljs_time/extend.cljs#L1-L2
Hello there,
I am new Clojure(script) world.
I needed a little with clojurescript, so I am fetching information from data api which contain html tags <br/>
\r\n
that are in hashmap as values. This is so that lines breaks after at desired sentence in HTML dom.
I expect the line to break everytime this <br/>
\r\n
, however this is what I am getting
Whenever has this tag <br/>
This is what i get
Lorem ipsum dolor sit amet, consectetur adipiscing elit. <br/> Quisque nisl eros, pulvinar facilisis justo mollis.
this is when I have \r\n
This is what i get
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque nisl eros, pulvinar facilisis justo mollis.
Thanks in advanceA lot of HTML rendering engines are reluctant to render âexternalâ strings as HTML due to the danger of hacking, so they render â</br>â as a literal string </br>
instead of as a break. I would expect the What are you using to generate the HTML for your DOM?\r\n
to work though.
Oh derp, no, HTML treats \r\n
like a single space character unless youâre inside a <pre>
block or similar.
Ok, React definitely wonât let you inject a â</br>â into your DOM. At the javascript level it will let you call dangerouslySetInnerHtml()
to do something like that, but I wouldnât take the chance myself. I havenât used helix, let me look that up real quick and Iâll make a suggestion.
Ok, quick and dirty, hereâs an example with my fake d/div
function
(def test-string "Lorem ipsum</br>dolor sit amet\r\nQuisque nisl eros.")
=> #'user/test-string
(defn my-block
[from-api]
(let [lines (clojure.string/split from-api #"\r\n|\n|</br>")]
(apply div (for [line lines] (div line)))))
=> #'user/my-block
(print (my-block test-string))
<div>
<div>Lorem ipsum</div>
<div>dolor sit amet</div>
<div>Quisque nisl eros.</div>
</div>
=> nil
Oh, sorry, whatever youâre using to generate your DOM HTML. I was looking at the docs for helix, and I saw they were using a function d/div
, so I made a fake/demo version of it because I didnât want to build a whole helix project just for a quick demo. đ
Basically what I did was use clojure.string/split
plus a regular expression to split the incoming string into separate strings wherever there was a \r\n
or a </br>
, and then render each string separately.
Couple extra lines, but it makes React feel safer.