code-reviews

jayesh-bhoot 2019-07-24T05:34:46.006800Z

Hi. Any improvement tips for my first ever clojurescript code? https://github.com/jayesh-bhoot/enforce-browser-fonts/blob/master/cljs-version/src/ebf/bg.cljs

dmaiocchi 2019-07-24T07:11:58.008800Z

You could create a higher function where you take as arg state and modification func as 2nd parameter (set and sync)

👍 1
dmaiocchi 2019-07-24T07:13:24.010100Z

So modifystaye(state modifystate) modifystate is a func

dmaiocchi 2019-07-24T07:14:40.011100Z

But is more a style thing imho is good otherwise!

dmaiocchi 2019-07-24T07:16:10.012Z

You could use let to improve readability

dmaiocchi 2019-07-24T07:16:18.012300Z

At line 43

jayesh-bhoot 2019-07-24T11:54:18.013300Z

So at least I am on the right track! I have kept the code as it is for now, and will integrate the higher order functions as I learn more.

dmaiocchi 2019-07-24T13:03:08.014400Z

@jayesh-bhoot imho, what can be improve also, is the (.set) interoperability with clojurescript

dmaiocchi 2019-07-24T13:03:18.014900Z

I have not used clojurescript sofar but http://cljs.github.io/api/cljs.core/setBANG

dmaiocchi 2019-07-24T13:04:11.015600Z

imho in theory you should the .functionNative when needed and take what is already there

dmaiocchi 2019-07-24T13:05:07.016800Z

e.g with clojure, .Foo is most of the time wrapped in a constructor of clojure which read more the clojureway , so it is more avoided then used. It is used when needed mostly 😁

dmaiocchi 2019-07-24T13:05:38.017400Z

but if you have primitive in clojurescript that does the same thing, i would personally prefer them. hope it helps

jayesh-bhoot 2019-07-24T13:37:30.020900Z

Oh I agree. To the point that I was considering using core.aync channel instead of the JS promise mechanism (through promise->chan and chan->promise endpoints). May be in the next project.

dmaiocchi 2019-07-24T13:39:13.024Z

I think core async is best in clojurescript

jayesh-bhoot 2019-07-24T13:39:15.024100Z

Regarding .set, instead of a simple variable assignment, its an asynchronous set operation, returning a Promise. As in its not exactly a standard JS assignment, but a weird Mozilla API design.

dmaiocchi 2019-07-24T13:39:37.025200Z

In clojure one could rely also on Java queue

jayesh-bhoot 2019-07-24T13:39:45.025700Z

So I couldn't have used the cljs native set! here

dmaiocchi 2019-07-24T13:40:05.026400Z

But in Javascript afaik there isnt such primitives that is really cool

dmaiocchi 2019-07-24T13:40:29.027100Z

So mentally typo:grin:

jayesh-bhoot 2019-07-24T13:40:57.028Z

> I think core async is best in clojurescript I agree. I an already itching to replace my current implementation

1
dmaiocchi 2019-07-24T13:42:17.030Z

A OK thx for clarification about set! Discovered something new

👍 1
jayesh-bhoot 2019-07-24T13:47:50.031700Z

Check this for more clarification - https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/browserSettings/useDocumentFonts#examples Its an API specific thing. Makes one pull their hair out. 😁

1