Fork me on GitHub
#clojurescript
<
2020-03-14
>
juri09:03:00

I have an event listener for deviceorientation. And when I get the DeviceOrientationEvent (.stringify js/JSON ev) gives {"isTrusted":true} , and yet, if I do (.-alpha ev) I get the correct angle. Why is alpha not included in the JSON?

p-himik10:03:10

Because Object.keys(deviceOrientationEvent) is just ['isTrusted'].

juri10:03:34

Hmm, yes, that's true also. But I don't understand why. Although I'm still learning js too. Is there any other way that I could get the alpha, beta and gamma too, other than getting them one by one (.-alpha ev) etc?

p-himik11:03:22

As to why - that's because DeviceOrientationEvent is not a plain JS object, it's an object with a constructor and a prototype. As to how to do it - just pass a JS array of the fields that you want to get as the second argument to stringify:

> JSON.stringify(e, ['isTrusted', 'absolute'])
"{"isTrusted":false,"absolute":false}"

oliver15:03:34

Hi, I'm having trouble creating and deleting inputs reactively (i.e. by manipulating a state atom). The problem only arises if I also want to bind the content of these inputs to the same atom using reagent-forms… I've posted a minimal example and analysis on Stackoverflow… would be great if any of you could take a look: https://stackoverflow.com/questions/60677426/reactive-adding-removing-inputs-with-reagent-forms

lilactown22:03:03

are there any monadic async libs for Clojure(Script)?