Fork me on GitHub
#clojurescript
<
2020-06-24
>
Rabie01:06:58

Hello, This is my first clojure or even slack question ever so please let me know if this is not the right channel or if I'm not asking the question the right way. So here is my problem. I'm making a checkers game to learn reframe and I made a subscription to show the pieces on the board. Here is a screenshot of my code The first way I wrote the subscribtion does the job just fine. However from the course of Eric Normand I understand that it is bad to call a subrscription within the let command and we should use de-duplication. This is what I tried to do with the second formulation on line 11. However for some strange reason the piece_dict variable contains nil and not the subscription [:piece row :col] I have two questions with respect to that: 1. What is wrong with my second formulation and why doesn't piece_dict contain the previous subscription 2. why is it that the first formulation is bad?

cjsauer01:06:11

Welcome @U015631CK4M 👋 You might try asking over in #re-frame.

Rabie02:06:31

Thanks I didn't know there was this channel

jrychter11:06:59

Has anybody run into the "SCRIPT1053: Const must be initialized" problem with Internet Explorer? My ClojureScript app stopped working on IE recently, and I'm not even sure where to start looking...

p-himik11:06:57

Does it point to some code that looks like for (const i = ...)?

jrychter11:06:16

It might (and probably does), but I'm seeing this in a compiled app for the moment, so I have no idea.

p-himik11:06:42

I think at some point the CLJS compiler has started to emit the code like that, and IE doesn't support it.

thheller12:06:32

that is incorrect. the CLJS compiler does not emit that code but the Closure Library has some code that uses it.

thheller12:06:39

regular CLJS does not transpile during development I believe but it should be fine in release builds?

p-himik12:06:30

Ah, I see. Thanks!

jrychter13:06:52

Well, I do use :advanced compilation — and the problem appeared recently. I've been wondering if anybody else noticed. IE 11 is still an officially supported browser, unfortunately.

thheller13:06:57

is this shadow-cljs?

thheller13:06:20

if not the setting is :language-out :es3 in your build compiler options

jrychter13:06:36

I use lein cljsbuild. Will try that.

jrychter13:06:13

Would there be any serious implications to limiting to es3? Big performance loss, major regressions?

Karol Wójcik13:06:56

@U0511PZ1R Increased bundle size. Imo es5 should be "good enough" to cover ie11.

jrychter13:06:23

According to http://caniuse.com, es5 is supported in IE11. But it has a problem with const declarations in for loops.

Karol Wójcik13:06:47

@U0511PZ1R const is not a part of es5 specification. That's es6.

Sung11:06:39

Is there a var-get alternative in clojurescript?

dnolen13:06:55

there are no vars so few var related thing exist at runtime - you can do some of these things via macros but you need to understand the implications - except for a small number of use cases I would avoid it

Sung13:06:40

thank you

kenny15:06:16

I'm working with goog.ui.Tooltip. To change the tooltip's position, I think I need to set the "positioning strategy." In https://google.github.io/closure-library/api/goog.ui.Tooltip.html#getPositioningStrategy for getPositioningStrategy, it says you can "Override in subclasses to customize the way repositioning is done." I'm not entirely sure how this should be done in cljs. I have tried the below snippet but it causes some goog assertion errors to get thrown which look like the result of some null or missing properties. I'm not sure if this is the correct way to do it & the assertion errors need to be fixed or if this is the wrong approach and using the correct approach would not result in failed assertions. Any ideas on how this can be done?

(js/Object.create
  (.-prototype goog.ui.Tooltip)
  #js{:getPositioningStrategy #js{:configurable true
                                  :value        (fn [_]
                                                  ;; overriden method
                                                  )}})

thheller15:06:56

@kenny how do you show the tooltip? you don't really need to subclass anything normally?

kenny15:06:19

It eventually https://github.com/google/closure-library/blob/5359ebb8cd7882c3195db548edb660f987988568/closure/goog/ui/tooltip.js#L640 and will either pass opt_pos (an arg passed to the positionAndShow_ fn) otherwise default to this.getPositioningStrategy. If I walk the method calls back, there are two places that could pass the opt_pos arg that would get to positionAndShow_ (it gets passed down by a call to startShowTimer). One of https://github.com/google/closure-library/blob/5359ebb8cd7882c3195db548edb660f987988568/closure/goog/ui/tooltip.js#L705 does not pass opt_pos at all and https://github.com/google/closure-library/blob/5359ebb8cd7882c3195db548edb660f987988568/closure/goog/ui/tooltip.js#L766 passes it but implicitly calls getPositioningStrategy haha!

kenny15:06:52

So, afaict, there is no way to customize the tooltip position via a setter on goog.ui.Tooltip. The docs imply this in the https://google.github.io/closure-library/api/goog.ui.Tooltip.html#getPositioningStrategy: "Return a Position instance for repositioning the tooltip. Override in subclasses to customize the way repositioning is done."

kenny15:06:34

I can also get somewhat close with this:

(defn TT
  []
  (this-as this
    (prn "construct")
    (js/Reflect.construct goog.ui.Tooltip #js [] TT)
    this))

(set! (.-prototype TT)
      (.-prototype goog.ui.Tooltip))

(doto (TT.)
  (.setText text)
  (.attach element-id))
I however, will get the same "Assertion failed: goog.dom.setTextContent expects a non-null value for node" error thrown.

kenny15:06:58

Oh wow, this appears to work!

(defn TT
  [{::keys [position]}]
  (this-as this
    (prn "construct")
    ;(js/Reflect.construct goog.ui.Tooltip #js [] TT)
    (goog.ui.Tooltip.call this)
    (set! (.-ttPosition ^js this) position)
    this))

(set! (.-prototype TT)
      (js/Object.create (.-prototype goog.ui.Tooltip)
                        #js{:getPositioningStrategy #js{:configurable true
                                                        :value        (fn [asd]
                                                                        (this-as this (.-ttPosition ^js this)))}}))
(doto (TT. {::position (goog.positioning.AnchoredPosition.
                         (.getElementById js/document element-id)
                         corner)})
  (.setText text)
  (.setShowDelayMs show-delay-ms)
  (.attach element-id))

benny21:06:35

is there a recommended way to pass an async/await async handler to javascript? for example, how would i reproduce this in cljs?

messaging().setBackgroundMessageHandler(async remoteMessage => {
  console.log('Message handled in the background!', remoteMessage);
});

Jimmy Miller21:06:54

That function isn't doing anything with async/await. the async there is completely unneeded.

Jimmy Miller21:06:10

You can just pass a normal function.

Jimmy Miller21:06:44

In general, unless you pull in some library, async/await is just sugar for promises and you can deal with those using normal js interop in clojurescript.

thheller23:06:33

thats not entirely true here

thheller23:06:03

it is an async function so it is a function that always returns a promise

thheller23:06:21

which may or may not be relevant

thheller23:06:00

I don't know about that part

thheller23:06:58

but yeah basically if the function demands it just return a promise

thheller23:06:06

if its fine with getting nil use a simple function

benny15:06:57

thanks guys