-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dali.transform.load load-edn load-json
- Loading branch information
awb99
committed
Nov 9, 2024
1 parent
34b40b5
commit 7fcf6d2
Showing
6 changed files
with
70 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{:first-name "Walter" | ||
:last-name "Schlemmel"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
(ns demo.person) | ||
|
||
(defn person [{:keys [first-name last-name]}] | ||
[:p "FirstName: " first-name " LastName: " last-name]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
(ns dali.transform.load | ||
(:require | ||
[taoensso.timbre :refer-macros [info warn error]] | ||
[promesa.core :as p] | ||
[ajax.core :as ajax] | ||
[clojure.edn :as edn])) | ||
|
||
(defn wrap-promise | ||
[AJAX-TYPE url params] | ||
(p/create | ||
(fn [resolve reject] | ||
(AJAX-TYPE url | ||
(merge params | ||
{:handler (fn [response] | ||
(resolve response)) | ||
:error-handler (fn [error] | ||
(reject error))}))))) | ||
|
||
(defn GET | ||
([url] (GET url {})) | ||
([url params] (wrap-promise ajax/GET url params))) | ||
|
||
(defn parse-edn [s] | ||
(if (string? s) | ||
(edn/read-string s) | ||
s)) | ||
|
||
(defn load-edn [{:keys [url] :as opts}] | ||
(info "loading edn from url: " url " opts: " opts) | ||
(let [load-promise (GET url)] | ||
(-> load-promise | ||
(p/then (fn [data] | ||
(info "url " url " loaded successfully. ") | ||
(parse-edn data))) | ||
(p/catch (fn [err] | ||
(error "could not load edn from url " url " err: " err)))))) | ||
|
||
(defn parse-json [s] | ||
(-> s js/JSON.parse js->clj)) | ||
|
||
(defn load-json [{:keys [url] :as opts}] | ||
(info "loading json from url: " url " opts: " opts) | ||
(let [load-promise (GET url)] | ||
(-> load-promise | ||
(p/then (fn [data] | ||
(info "url " url " loaded successfully. ") | ||
(parse-json data))) | ||
(p/catch (fn [err] | ||
(error "could not load json from url " url " err: " err)))))) | ||
|
||
|