Skip to content

Instantly share code, notes, and snippets.

@geraldodev
geraldodev / promises-cljs.md
Created Aug 16, 2022 — forked from pesterhazy/promises-cljs.md
Promises in ClojureScript
View promises-cljs.md

Chaining promises

Chaining promises in ClojureScript is best done using the thread-first macro, ->. Here's an example of using the fetch API:

(-> (js/fetch "/data")
    (.then (fn [r]
             (when-not (.-ok r)
               (throw (js/Error. "Could not fetch /data")))
             (.json r)))
@geraldodev
geraldodev / use_fetcher.cljs
Created Jul 9, 2022
react-router use-fetcher hook "beanified" use-fetcher hook that encaspulate keeps you from using useLoaderData just for getting the result of the router load function
View use_fetcher.cljs
(ns crudis.ui.hooks.use-fetcher
(:require
["react-router-dom" :refer [useLoaderData useFetcher]]
[cljs-bean.core :refer [bean]]
))
(defn use-fetcher
[]
(let [fetcher (useFetcher)
first-page (useLoaderData)
@geraldodev
geraldodev / countries.cljs
Created Jun 26, 2022
react-router-dom useLoaderData example
View countries.cljs
(ns crudis.ui.routes.countries
(:require
["react-router-dom" :refer [useLoaderData]]
[crudis.util.helix :refer [defnc]]
[helix-window.fixed-size-list :as fsl]
[helix.core :as hx :refer [$ <> fnc]]
[helix.dom :as d :refer [div]]
[paqueta.fetch :as fetch]
[promesa.core :as p]
))
@geraldodev
geraldodev / client.cljs
Created Jun 26, 2022
root cljs app defining DataBrowserRouter from react-router
View client.cljs
(ns crudis.client
(:require
["react-dom" :as rdom]
["react-dom/client" :refer [createRoot]]
["react-router-dom" :refer [DataBrowserRouter Route]]
[crudis.util.helix :refer [defnc]]
[crudis.ui.root :as root]
[crudis.ui.routes.countries :as countries]
[helix.core :refer [$]]
[helix.dom :as d]
View row_virtualizer_example.cljs
(ns crudis.ui.root
(:require
["@tanstack/react-virtual" :refer [useVirtualizer]]
["react" :as React]
[goog.object :as gobj]
[helix.core :as hx :refer [defnc $ <> fnc]]
[helix.dom :as d :refer [div a button]]
[helix.hooks :as hooks :refer [use-state]]
[paqueta.fetch :as fetch] ;; lambdaisland fetch
))
@geraldodev
geraldodev / button.cljs
Created May 18, 2022
stitches button in cljs
View button.cljs
(ns stitches.componentes.button
(:require
[applied-science.js-interop :as j]
[stitches.config :refer [styled jsvec-to-obj]]
))
(def Button
(styled
"button"
(jsvec-to-obj
@geraldodev
geraldodev / jsx_to_helix.clj
Created May 16, 2022
Generates helix clojurescript output of a React JSX input file. The files are defined on the input-jsx and output-clj variables. the executing function is on the first line of the comment
View jsx_to_helix.clj
(ns jsx-to-helix.core
(:require
[clojure.data.xml :as xml]
[clojure.edn :as edn]
[clojure.java.io :as io]
[clojure.pprint :refer [pprint]]
[clojure.walk :as walk]
[superstring.core :as str]
)
(:import [clojure.data.xml.node Element]))
View heading.cljs
(ns stitches.componentes.heading
(:require
["lodash.merge" :as js-merge]
["react" :as React]
[applied-science.js-interop :as j]
[crudis.util.helix :refer [defnc]]
[helix.core :refer [$]]
[stitches.componentes.text :refer [Text]]
))
@geraldodev
geraldodev / helix-autocomplete.cljs
Last active Nov 27, 2020
Thin layer over mui autocomplete.
View helix-autocomplete.cljs
(ns app.helix_autocomplete
(:require
["@material-ui/lab/Autocomplete" :default Autocomplete]
["@material-ui/core/TextField" :default TextField]
["react" :as r]
[goog.object :as gobj]
))
(defnc AutocompleteHelix
@geraldodev
geraldodev / mui-autocomplete.cljs
Created Nov 20, 2020
mui Autocomplete with helix. The render-input node needs to be created with plain react
View mui-autocomplete.cljs
(ns app.ui.contratualizacao.regra
(:require
["@material-ui/lab/Autocomplete" :default Autocomplete]
["@material-ui/core/TextField" :default TextField]
["react" :as r]
[goog.object :as gobj]
))
($ ^:native
Autocomplete