Skip to content

Commit

Permalink
cljs-ajax POST and PUT added
Browse files Browse the repository at this point in the history
  • Loading branch information
awb99 committed Sep 5, 2023
1 parent 2f67990 commit 35558c2
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 25 deletions.
7 changes: 5 additions & 2 deletions resources/ext/ajax.edn
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{:name "ajax"
; build
:lazy false
:cljs-namespace [pinkgorilla.repl.cljs.load]
:cljs-ns-bindings {'ajax.core {'GET pinkgorilla.repl.cljs.load/http-get}}}
:cljs-namespace [pinkgorilla.repl.cljs.ajax]
:cljs-ns-bindings {'ajax.core {'GET pinkgorilla.repl.cljs.ajax/http-get
'POST pinkgorilla.repl.cljs.ajax/http-post
'PUT pinkgorilla.repl.cljs.ajax/http-put
}}}
27 changes: 27 additions & 0 deletions src/pinkgorilla/repl/cljs/ajax.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
(ns pinkgorilla.repl.cljs.ajax
(:require
[promesa.core :as p]
[clojure.edn :as edn]
[ajax.core :refer [GET POST PUT]]
[clojure.string :as str]))

(defn- make-promise [AJAX-TYPE]
([url]
(make-promise url {}))
([url params]
(p/create
(fn [resolve reject]
(AJAX-TYPE url
(merge params
{:handler (fn [response]
(resolve response))
:error-handler (fn [error]
(reject error))}))))))

(def http-get (make-promise GET))
(def http-post (make-promise POST))
(def http-put (make-promise PUT))




23 changes: 0 additions & 23 deletions src/pinkgorilla/repl/cljs/load.cljs

This file was deleted.

0 comments on commit 35558c2

Please sign in to comment.