clojurescript | source content for the Practicalli , Clojurescript book
kandi X-RAY | clojurescript Summary
kandi X-RAY | clojurescript Summary
Content for the Practicalli ClojureScript book. Warning:: Requires major update Requires a major update to catch up with changes in Clojure and ClojureScript, especially around shadown-cljs which is not yet covered. An example that is still relevant is the TicTacToe game with ClojureScript, Reagent and Scalable Vector Graphics (SVG). This workshop is aimed at those new to writing client-side web applications using the ClojureScript programming language, a functional programming language based on Lisp and compiled to JavaScript. ClojureScript and client side development are covered in a highly practical way, so you can evaluate where ClojureScript is useful in your own projects. This workshop guides you through the basics of client-side web development and functional programming in ClojureScript. Design approaches common to ClojureScript & React will be covered along the way.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of clojurescript
clojurescript Key Features
clojurescript Examples and Code Snippets
Community Discussions
Trending Discussions on clojurescript
QUESTION
I am trying to build a simple client-server system with Clojure (server) and ClojureScript (client).
The server side is OK (everything is green on the browser's console, no CORS problems, etc.); the response is plain text ("true" or "false"). On the client side I am using basically the function included in the official cljs-http website
...ANSWER
Answered 2021-Jun-06 at 13:46It's Saturday morning and I'm feeling lazy so I didn't run this, but this should work:
QUESTION
I'm building a web app using Clojure and ClojureScript and I need it to have authentication based on a white-list of organization. For example, let's say I've added University1.edu to my white-list, and when a student from that university wants to login to my web app, they would be redirected to their own universities login system. After that I would just a confirmation of whether or not they successfully logged in there and maybe create a session, cookies, or or something for them.
Is that possible and if so, how can I implement that?
...ANSWER
Answered 2021-May-23 at 01:30Some common ways to implement this authentication schemes are OAuth2 and OpenID, which are commonly used in websites were you can log in with your social / Twitter / Facebook / Google account.
Using OAuth for instance, you register your website in some developer portal (depending on the service that you'll use to authenticate) and obtain a token that that you'll use during the login flow and after logging on their portal, users are redirected back to your site.
In order for this to work, every organization (eg. University1) needs to be a provider of this authentication scheme, so that's something you'll need to research.
In Clojure there is a couple of options: the buddy library seems to be a popular choice, but you could also use some Java libraries through interop.
QUESTION
This might sound a stupid question, but how do I turn a piece of hiccup into html in a ClojureScript reagent application?
I want something like this :
...ANSWER
Answered 2021-May-03 at 06:21I'm not sure why you would want to do this, but it appears one answer is to use the function:
Normally, your Reagent components only return Hiccup data, and you let reagent.dom/render
do all the hard work of reactively "rendering" only the changed components into the DOM.
P.S. When in doubt, you can often find documentation at cljdoc.org. Most Clojure projects have a direct link there from their GitHub page (Reagent does, for example). Or, you can go to cljdoc.org directly and search there.
QUESTION
Using clojurescript 1.10.758 and reagent 1.0.0, I am running into an error in which a file index.js tries to reference $jscomp
, which is not defined.
I've seen a number of Stackoverflow and Github issues related to $jscomp being undefined in the context of shadow-cljs, but I'm not using that.
The problem occurs when I use a development mode build with figwheel (using Leiningen with cljsbuild and the figwheel plugin), and also occurs if I use cljsbuild for a once-only development build. Strangely, if I use webpack to create a bundle, the problem does not occur.
Before I tried to make webpack work, I did have working code without webpack. Something I changed seems to have affected the non-bundled build. The only change I can thing of was to install react and react-dom using npm, and exclude those packages from reagent in Leiningen's dependencies. But undoing the exclusion didn't make the non-bundled code work again.
Any suggestions for how to cause $jscomp
to be defined when it's first needed?
ANSWER
Answered 2021-Apr-20 at 08:42$jscomp
is related to the Closure Compiler and the Polyfills it creates.
It might be enough to tweak the :language-out :es6
compiler options which is somewhat similar to the :output-feature-set
option used by shadow-cljs
. The best way to debug this is finding the actual code that is getting polyfilled and why. Might require digging through some compiled JS though.
shadow-cljs
uses the Closure Compiler more extensively than regular CLJS or figwheel but they also use it. Solutions that apply to shadow-cljs
pretty much apply to other tools as well. Just the settings may work a little differently.
QUESTION
I am trying to create a simple clojurescript which'll display the width of the browser window.
My app.cljs look like the following:
...ANSWER
Answered 2021-Apr-13 at 07:19In your (defn init [] ...)
you are creating a anonymous function and then immediately call it by having the extra parens ((fn [] ...))
. So the result of that function call is what you set!
as the onload
instead of the function itself. Just remove one pair of parens.
In your config you are setting :optimizations
and :externs
in the wrong level. They need to be under the :compiler-options
key. You do not need to set :optimizations
at all though, they default to :advanced
for browser release
builds.
browser-repl
starts a standalone browser REPL independenct of any build. If you want a REPL into your build use shadow-cljs cljs-repl frontend
.
QUESTION
I'm trying to do some (simple) plots in Clojure and it seems like Oz would be a great long term solution. However, I'm running into problems just trying to get the example code to run. PS I'm completely new to ClojureScript / Reagent / Hiccup ...
On the website it shows the following example code:
...ANSWER
Answered 2021-Apr-14 at 22:31Try something like the following, which uses my favorite template project.
QUESTION
What would be an elegant way to find the ba4
values for :foo
in a data structure like:
[[{:foo "ba1"}{:foo "ba2"}] [{:foo "ba3"}{:foo "ba4"}]]
and add the :bif "baf"
key and value so the map(s) containing the key/value I sought so I had:
[[{:foo "ba1"}{:foo "ba2"}] [{:foo "ba3"}{:foo "ba4" :bif "baf"}]]
?
This is the main thing I am trying to figure out; I do wonder about how you would do this if there were multiple levels of nested maps, but that will be next for me to understand.
I have, I think, seen various libraries out there for tackling this sort of thing and I'm not at all against using them, though they would have to work in ClojureScript.
I am trying to update a Reagent atom such that classes will change on a UI element.
...ANSWER
Answered 2021-Apr-02 at 07:04Clojure is quite convenient for defining mini-languages for these sorts of things. A general and fairly reusable solution does not have to be much longer than a specialized one. Here is one suggestion if you are not interested in using a library.
Essentially, you want a function to update a datastructure. This function could be expressed using elementary functions of the same kind that serve as building blocks, making up a mini-language that I referred to before. In this example, the building blocks will be vector-scanner
and map-decorator
. We combine these functions into my-path
that will perform the full update.
QUESTION
I am trying to build on the Pedestal tutorial app available here.
I am trying to add cljs functionality and trying to setup a unified clojurescript and clojure environment.
My deps.edn file looks as follows:
...ANSWER
Answered 2021-Mar-20 at 12:38See http://pedestal.io/cookbook/index#_how_to_serve_static_resources. Note in particular that Pedestal's http/resource-path holds not a file-system location, but rather a URL path prefix by which Pedestal should recognize things it should redeem from the classpath.
QUESTION
What is the best way in Clojure (actually ClojureScript) to accomplish the following:
- A mutable collection of elements
xs
, each of typeT
(T
is a map, if we want to be specific) - A "selected element" among them,
x
, which alternates between variousxs
or a "none selected" state. The number of selected items is either 1 or zero. xs
andx
will have event listeners listening to them: some listen for any change inxs
; some listen to any change inx
. (That is, they listen for both an update in the state of the selected item, as well as a switching of which item is selected.) (I'm actually using the Reagent wrapper for React, so this affects when components will update.)- Methods to edit
x
(don't need to edit non-selectedxs
, though need to be able to add newxs
) - Given an element in
xs
, a method to select it. (Including the case of select "none")
Possibilities I've thought of so far:
- Make
xs
an atom which is a vector ofT
s, and make sure everyT
element knows its own index. Replacex
withx_idx
which stores the index of the selected item (ornil
). Selecting an element just means getting its index and changingx_idx
to that index, both of which are constant-time ops. Downsides to this are that it makes the structure a little less elegant and simple: I'm always passing around the index of the selected item, and every operation I want to do has to work with the index instead of the item itself, as it would like to. Since myT
objects are small, it would be more pleasing to just have a "selected object" variable which is of typeT
. - Make
xs
an atom vector andx
an atom which stores aT
. Nowx
is aT
, which is nice, but when I want to update info aboutx
, I have to make two calls toreset!
orswap!
: one forx
and one for the element inxs
whichx
represents. Inelegant for obvious reasons. And I have to do these in quick succession or else there will be an inconsistency in the data: in between the two calls, the event listeners listening toxs
will see the selected item in one state, and the ones listening tox
will see it in another state. - Give
T
elements a field to tell if they're selected or not, and get rid ofx
. This would be right if multiple items could be selected at once, but since only one item can be selected, it just makes me do a linear search every time I want the selected item, which sucks.
The point of this question is not to solve some particular issue (any of the possibilities above work fine for the scope of the small project I'm working on), but to learn about Clojure data structures. This seems like a common enough situation that there would be some structure around it. Responses along the lines of "you should be trying to answer a different question entirely..." are welcome.
...ANSWER
Answered 2021-Mar-15 at 20:49You (I) want to look into cursor
s and reaction
s, two of the more advanced features of Reagent atoms. They can be used to have a collection and a selected element inside it which is automatically updated. See here for example.
Suppose you have a r/atom
holding vector of objects and you want to have a selected object which can change, and which is directly editable. One way to achieve this is to keep an atom storing the index of the selected item and then
QUESTION
I'm trying to create a multipage application with clojurescript. For the react stuff I'm using the helix library. For the reloading I'm using shadow-cljs.
When trying to use the react-router-dom like in javascript it doesn't work.
Here's my code:
...ANSWER
Answered 2021-Mar-07 at 18:08I managed to solve the issue: Because BrowserRouter, Route and Switch aren't valid React components one has to insert them with the $ macro:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install clojurescript
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page