Merge with map literal
(merge a {:a 1 :b 2})
-> (assoc a :a 1 :b2)
(-> foo (merge {:foo :bar})
-> (-> foo (assoc :foo :bar))
Reasoning:
- Performance
- Easier to read?
(def start (atom nil)) | |
(def log (atom [])) | |
(defn latency-test [] | |
(let [a (r/atom 0)] | |
(fn [] | |
(let [[b update-b] (react/useState 0)] | |
(react/useEffect | |
(fn [] |
alias: TV valot | |
description: "" | |
trigger: | |
- platform: state | |
entity_id: | |
- media_player.tv | |
not_to: | |
- unknown | |
for: | |
seconds: 5 |
(ns app.dev.shadow | |
(:require [shadow.cljs.devtools.api :as shadow] | |
[clojure.edn :as edn])) | |
;; Run this with: | |
;; npx shadow-cljs clj-run app.dev.shadow/watch | |
(set! *warn-on-reflection* true) | |
(defn watch |
var vm = require("vm"); | |
var fs = require("fs"); | |
function nodeGlobalRequire(file) { | |
var _module = global.module, | |
_exports = global.exports, | |
exportedRequire = false; | |
// to circumvent Node.js environment detection in bundled libraries | |
global.module = undefined; |
(merge a {:a 1 :b 2})
-> (assoc a :a 1 :b2)
(-> foo (merge {:foo :bar})
-> (-> foo (assoc :foo :bar))
Reasoning:
(ns example.react-konva-image | |
(:require [reagent.core :as r] | |
;; This presumes Shadow-cljs (or cljsjs packages with correct definitions) | |
[react-konva :refer [Stage Layer Image]] | |
[use-image :as use-image])) | |
(defn lion-image [] | |
(let [[image] (use-image "https://konvajs.org/assets/lion.png")] | |
(r/as-element [:> Image {:image image}]))) | |
;; or, without Reagent hiccup -> React elements step, directly creating React element: |
(defn router-component [match] | |
(let [[view-component & nested-view-components] (:views match)] | |
(if view-component | |
[view-component (assoc match :views nested-view-components)]))) | |
(defn topics-view [match] | |
[:div | |
[:div "List of topics..."] | |
;; Nested router, renders nothing or topic-view if in :topic |
Reagent uses async rendering model. Reagent uses browsers requestAnimationFrame
to schedule render calls:
https://reagent-project.github.io/news/reagent-is-async.html
[:input {:default-value "foo" :on-change #(js/console.log (.. % -target -value))}]
Uncontroller input is an input which value is not updated by Reagent/React if the value set in the code changes. After initial render, the value is only changed by users interactions.
Currently libraries need to write some logic to load JS libraries from various places. For example Reagent supports:
js/React
, js/ReactDOM
, js/ReactDOMServer
and js/createReactClass
require
when using Node targetBecause the default is Cljsjs, Reagent namespaces depend on cljsjs namespaces like cljsjs.react
. This means that to use Reagent
with option 2. requires creating empty stub namespaces that provides these.
Builds can be triggered (in addition to commits to the repo), by Travis cron daily, or with HTTP endpoint called by other builds, in other projects: https://docs.travis-ci.com/user/triggering-builds/
clojure/clojurescript
would trigger process (cljs-oss/clojurescript
) to build the new jar file.