This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-05-05
Channels
- # announcements (7)
- # babashka (20)
- # beginners (130)
- # bristol-clojurians (1)
- # cider (14)
- # clj-kondo (7)
- # cljdoc (14)
- # cljs-dev (15)
- # cljsrn (16)
- # clojars (11)
- # clojure (190)
- # clojure-dev (4)
- # clojure-europe (7)
- # clojure-italy (9)
- # clojure-nl (3)
- # clojure-romania (6)
- # clojure-uk (51)
- # clojurescript (44)
- # component (4)
- # conjure (28)
- # cursive (1)
- # data-science (4)
- # datascript (1)
- # datomic (30)
- # duct (4)
- # emacs (1)
- # figwheel (4)
- # fulcro (56)
- # graalvm (4)
- # helix (51)
- # jackdaw (2)
- # jobs-discuss (12)
- # joker (4)
- # lambdaisland (1)
- # local-first-clojure (1)
- # meander (73)
- # mid-cities-meetup (2)
- # nrepl (4)
- # off-topic (43)
- # pathom (56)
- # re-frame (37)
- # reagent (26)
- # shadow-cljs (161)
- # slack-help (9)
- # spacemacs (1)
- # tools-deps (18)
- # xtdb (18)
I am trying to convert some javascript into clojurescript and I am not sure if I am doing it right. I don’t get any errors but I think I might be doing something wrong. I am trying to convert the following as can be found here: https://docs.amplify.aws/lib/auth/start/q/platform/js#re-use-existing-authentication-resource
import Amplify, { Auth } from 'aws-amplify';
Amplify.configure({
Auth: {
region: 'XX-XXXX-X',
userPoolId: 'XX-XXXX-X_abcd1234',
userPoolWebClientId: 'a1b2c3d4e5f6g7h8i9j0k1l2m3',
}
});
// You can get the current config object
const currentConfig = Auth.configure();
I got:
(defn configure []
(.configure
Amplify
(clj->js {Auth {:region "eu-west-1"
:userPoolId "eu-west-1_xxxxxxx"
:userPoolWebClientId "xxxxxxxxxxxxx"}}))
(.configure Auth))
Is thar correct?
Thanks 🙂you could create js objects directly
#js {:Auth #js {:region ...}}
in your example above Auth
should be :Auth
Oh nice, I wasn’t aware of #js
, thank you
hi! Is there a way I could integrate something like this into my re-frame application? https://github.com/elrumordelaluz/reactour This is the code I'd need to "translate":
import React from 'react'
import Tour from 'reactour'
class App extends Component {
// ...
render (
<>
{ /* other stuff */}
<Tour
steps={steps}
isOpen={this.state.isTourOpen}
onRequestClose={this.closeTour} />
</>
)
}
const steps = [
{
selector: '.first-step',
content: 'This is my first Step',
},
// ...
]
yeah, I don't see any immediate reason why not. Did you give it a try and getting errors? Only cumbersome part is getting npm dependencies to work correctly, but there is bunch of guides online on how to get that to work, depends on what build tool you're using too
Yes, my main concern was how to translate the "imports" and how to declare the library as a dependency. The solution to the first one I found it here: https://clojureverse.org/t/guide-on-how-to-use-import-npm-modules-packages-in-clojurescript/2298
And in shadow-cljs, importing the library as a dependency was as simple as npm install
in my project folder 😅
But all this was more difficult to find that I expected, given the wide availability of React components and how easy everything really was in the end...
(for any curious readers) I also used this as a reference: https://www.rockyourcode.com/how-to-build-a-markdown-preview-app-with-reagent/
congratulations 🙂
I'm trying to get a hold of a map from a parent window ( js/window.opener
). Everything looks fine, except that something weird is happening with the keys:
;; Define the map in the parent window
(when-not js/window.opener
(def test-map {:a 1}))
;; In the child window, try to get a hold of the map
(when-let [opener js/window.opener]
(when (not= js/window opener)
(prn (assoc (into {} (js-get-in js/window.opener ["mynamespace" "test_map"]))
:a 2))))
{:a 1, :a 2}
I find myself with two (2) :a
keys.
Bug? Feature? I'm doing everything wrong? 😛Oh, and the into
is necessary, otherwise all I see when printing the map is #object[Function]
try checking the types of the keys - maybe they both print as :a
but aren't equal?
Both are of type 'cljs.core/Keyword`, but they aren't equal.
aha - as an optimization clojure does identity equality for keywords (and attempts to ensure only one of each keyword ever exists) - but by loading cljs twice you can get two of a keyword that aren't equal
I think I understand now
each window is it’s own JS “realm” or context - you cannot share data structures between the two
Yes; I have small application opening a child window opening the same cljs code.
each window will have it’s own version of keyword, map, etc. and they won’t be compatible
like, you have a separate script tag in this window right? that loads all of cljs.core?
But I'm pretty sure I can share variables between parent/child windows. As for complex datastructure, I don't know.
I can print the list of keys in a map, but they are never equal from one window to the next. 😕
Hmm... then I wonder if I can simply copy the context from the parent to the child. I'm gonna give it a try.
I bet you could even fix it by walking the hash-map and calling keyword
on every keyword
this isn’t just a CLJS problem, it’s a JS thing: https://stackoverflow.com/a/49832343/4379329
Yes there are multiple approaches to share serialized data, but unfortunately I have many identical MBs of data to share.
the way i have solved this recently is putting the data into localStorage or indexDB and using window.postMessage
to trigger read/write of the share datastore. a cool thing about localStorage which you may not know is that it emits and event in every window from the same domain. So if you have two tabs open for the same site you can use localStorage to write data and also communicate that data has been written. Good luck!
Of course this won't work for rich clojure types, but you can serialize to EDN or JSON or similar.
since the equality / return of keyword is based on interning
this doesn't come up for non-interned types (symbols, strings, hash maps) as they use value equality
I’m surprised that you can even use any data structures shared between the two windows. you’re pretty much relying on undefined behavior
(though you might need something fancier than calling keyword
, as that function might short circuit if the type is already keyword, and not catch that it isn't the interned one)
@lilactown it makes sense that it would work - it's two of the same cljs version, so the bytes have identical meaning, until you hit something that's not a value type (keywords)
lots of things rely on constructor or reference identity, which you don’t share between the two windows
it’s hard to know what will work and what will not without understanding the internals of cljs.core
OK -fair enough
of the "vanilla" data types - the things that work in edn without reader tags - I would expect keywords to be the gotcha, but then again it should be easy to verify what does or doesn't work for a given browser engine
sharing large amounts of data between windows is currently not a greatly supported thing
the way i have solved this recently is putting the data into localStorage or indexDB and using window.postMessage
to trigger read/write of the share datastore. a cool thing about localStorage which you may not know is that it emits and event in every window from the same domain. So if you have two tabs open for the same site you can use localStorage to write data and also communicate that data has been written. Good luck!