Fork me on GitHub
#reagent
<
2019-02-06
>
tomayerst08:02:13

Does anyone know if there is a way of catching the lack of a drop event when you drop a draggable outside a drop-target? I set some local-state when I start dragging and I want to revert it if I cancel the drag (or drop it elsewhere) but I cannot find a way to trigger it 😞

mccraigmccraig09:02:20

can you handle the event on window or document during the capture phase @tomayerst?

tomayerst09:02:48

@mccraigmccraig thanks, I have investigated that (and it may be where I end up) but I was trying to avoid making everything a drop target as it makes the visual feedback on the drag confusing. Also l would like to pick up hitting the 'esc' key too.

mccraigmccraig09:02:56

that wouldn't be making everything a drop target @tomayerst - but handling the event during the capture phase rather than the more normal bubble phase

mccraigmccraig09:02:00

that technique has gotten me out of similar difficulties in the past - i've never tried it with drag/drop though, so ymmv

tomayerst09:02:50

The thing is, as I understand it, if you are not over a drag target there is no drop event at all. But I am new to this so I may not understand.

mccraigmccraig09:02:51

ah, if there is no event then all bets are off

tomayerst10:02:12

Yeah 😞. I believe I am not alone in finding the HTML5 drag and drop API a bit weird.

WhoNeedszZz15:02:24

What is the Reagent equivalent of this?

john16:02:54

afaik, the json/ld stuff is not reagent (or react) specific. Do you want to dynamically inject that script into the head of your document? Does some lib depend on it being there?

john16:02:32

If so, you could injected it with something along the lines of this:

(def ld "{ `{ \"@context\": \"\" }` }")

(defn inject-ld [ld]
  (let [s (-> js/document (.createElement "script"))]
    (-> s .-text (set! ld))
    (-> js/document .-head (.appendChild s))))

WhoNeedszZz16:02:19

It's taken from the React Helmet documentation. So you put it as a child of the Helmet component

WhoNeedszZz16:02:46

Would this work?

WhoNeedszZz16:02:59

Part of my issue is I don't know how to view the resulting html. When viewing the page source it only shows the html before the injections

john16:02:24

well, that clj-<js needs to be clj->js, but that might work. Not sure if you need the stringification. And you might be able to put those backticks in the string, per the example... But I'm not really sure how Helmut is interacting with all the react lifecycle stuff.

john16:02:55

But unless you specifically need json/ld, I think you'd normally be inserting a regular javascript script text, in which case, cljs normally handles all that for you.

WhoNeedszZz16:02:19

That was a typo

WhoNeedszZz16:02:32

Unless I'm misunderstanding something the backticks are just because that's JS not CLJS so it's a JS literal

WhoNeedszZz16:02:10

The resulting JS has to be what I first pasted

WhoNeedszZz16:02:32

So the question is does what I last pasted transpile to that?

john16:02:12

And usually in cljs development, when using reagent, we lean on stuff like hiccup:

(html5
  [:head
   [:title "Acme Corp"]
   [:meta {:name "author"
           :content "Acme Corp, Inc., LLC"}]
   [:meta {:charset "utf-8"}]
   [:meta {:http-equiv "X-UA-Compatible" :content "IE=edge"}]
   [:meta {:name "viewport"
           :content
           "width=device-width, initial-scale=1.0, maximum-scale=1.0"}]
   (include-js
    "/js/extra-thing.js"
    (bust-cache "/js/compiled/main.js"))
   [:script
    {:src  (str "")
     :type "text/javascript"}]
   [:script google-analytics-string]
   ...])

WhoNeedszZz16:02:44

Which is what I have

WhoNeedszZz17:02:38

Still haven't resolved my issue so if anyone else can take a look I'd appreciate it

WhoNeedszZz17:02:13

I can't tell if the Google Structured Data Testing Tool is caching the page so it isn't picking up the change or if it isn't working the way I think it is

lilactown17:02:48

have you tried

[:script
 {:type "application/ld+json"}
 "{
            \"@context\": \"\"
    }"]

WhoNeedszZz17:02:33

The equivalent of that, yes

WhoNeedszZz17:02:08

I'm pretty sure the tool is just using a cached copy

WhoNeedszZz18:02:55

Yep, cache got busted and now it shows properly

👏 5
WhoNeedszZz18:02:02

So basically Google is dumb

frozenlock20:02:08

Is there a way to check if r/track is cached without executing the function?