Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cljs-ajax, slimmed down #9

Merged
merged 20 commits into from
Jun 11, 2021
Merged

Conversation

kloimhardt
Copy link
Contributor

exposes to Scittle:

ajax.core/GET
ajax.core/POST
clojure.core/random-uuid
cljs.reader/read-string (-> renamed to) clojure.core/read-string
reagent.core/as-element

@kloimhardt
Copy link
Contributor Author

I exposed read-string and random-uuid with and without sci/copy-var respectively. This is kind of arbitrary as I do not know when copy-var is necessary. @borkdude Mabe you can correct this?

@borkdude
Copy link
Collaborator

@kloimhardt Looks good. sci/copy-var is only needed when you want to have a reified var in the environment so you can use with-redefs, alter-var-root etc on them, but it's not really important for scittle I think.

@borkdude borkdude merged commit f5b0148 into babashka:main Jun 11, 2021
@borkdude
Copy link
Collaborator

@kloimhardt I now published an example:

https://borkdude.github.io/scittle/#cljs-ajax

@kloimhardt
Copy link
Contributor Author

@borkdude ... aaand there is the combined babashka+scittle Guestbook web-app example. It is here and has only two files: an 80loc backend (based on your since long available template) and the file guestbook-reagent/src/cljs/guestbook/core.cljs from Luminus.

I hope one day we will see this as the basis of a free-to-read opening chapter of some future edition of the book.

@borkdude
Copy link
Collaborator

@kloimhardt This is very exciting, thanks for making this. I will link it from the scittle page.

@borkdude
Copy link
Collaborator

I guess the cljs-ajax is kind of redundant now that all major browsers support the fetch API. That didn't occur to me a year ago.

@borkdude
Copy link
Collaborator

This is an example of the fetch API:

<html>
  <head>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/scittle.js" type="application/javascript"></script>
    <script type="application/x-scittle">
      (defn handler [response]
        (js/alert (str response)))

      (defn make-request []
       (-> (js/fetch "index.html")
           (.then #(.text %))
           (.then #(js/alert %))))

      ;; export function to use from JavaScript:
      (set! (.-make_request js/window) make-request)
    </script>
  </head>
  <body>
    <button onclick="make_request()">
      Click me!
    </button>
  </body>
</html>

@kloimhardt
Copy link
Contributor Author

Looking at your fetch example, it is obvious that removing clj-ajax from the Scittle canon is the way to go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants