Fork me on GitHub
Samuel McHugh16:03:16

I'm seeing some bizarre behavior with def regarding browser events in cljs. Try running a browser repl. (like the one at Run

(.addEventListener js/window
                   (fn [event]
                     (def e event)
                     (js/console.log (.getData (.-clipboardData event) "text/plain"))))
Try pasting some text. Now you should have your last 'paste' event bound to the var e . And you will have seen your pasted text logged to the console. If you eval e in your repl, you do see a ClipboardEvent, however if you actually look into what is in that ClipboardEvent, it's essentially "blank". You can check this with
(.getData (.-clipboardData e) "text/plain")
Anyone have any idea what's going on here? Does it regard some subtle difference in how def works in cljs, or something about events?


the has this to say about clipboard events > Access to the clipboard is performed using the standard DataTransfer methods to mutate the items on a ClipboardEvent's clipboardData attribute. One consequence of this is that these clipboard APIs can only access clipboard data in the context of a ClipboardEvent handler.


has nothing to do with def


it's just you're trying to access the data on a clipboard event outside of an event handler

🙌 1
Samuel McHugh08:03:15

thanks, good to know it's a consequence of the clipboard then. Thank you.