Skip to content

Instantly share code, notes, and snippets.

Juho Teperi Deraen

Block or report user

Report or block Deraen

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@Deraen
Deraen / linting_ideas.md
Last active Oct 4, 2019
Ideas for linter checks
View linting_ideas.md

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?
@Deraen
Deraen / react-konva-image.cljs
Last active May 29, 2019
React Konva example with Reagent
View react-konva-image.cljs
(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:
View reitit_nested_routing.cljs
(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
@Deraen
Deraen / Reagent_controller_inputs.md
Last active Apr 6, 2018
Notes about Reagent and problems with async rendering and controlled inputs
View Reagent_controller_inputs.md

Reagent uses async rendering model. Reagent uses browsers requestAnimationFrame to schedule render calls: https://reagent-project.github.io/news/reagent-is-async.html

Uncontrolled input

[: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.

@Deraen
Deraen / README.md
Last active Jul 10, 2017
WIP: Cljs foreign-lib requires brain dump
View README.md

Problem

Currently libraries need to write some logic to load JS libraries from various places. For example Reagent supports:

  1. (Default) Cljsjs packages which export js/React, js/ReactDOM, js/ReactDOMServer and js/createReactClass
  2. Npm packages, with require when using Node target

Because 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.

@Deraen
Deraen / README.md
Last active Jul 5, 2017
cljs-oss CI setup
View README.md
  1. One process for building Cljs and pushing resulting jar somewhere
  2. Process for each OS project for running tests against the jar
  3. One repo to save the build results

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.

View readme.md

Option 1.

https://github.com/Deraen/clojurescript/commit/bb94e566a8827d0356740491e2506fba02faa109

  • Load all js_transform.clj files in classpath
  • Problems:
    • files are not real namespaces (no ns)
    • load-reader will eval the code in file each time load-js-transforms! is called, which is each time cljs.closure/build is called
    • a js_transform.clj file is loaded even if js-transforms method from it is not needed
      • for example, if any lib in classpath has dep on cljsjs/babel-standalone
@Deraen
Deraen / build.clj
Created Apr 26, 2017
boot_static.clj
View build.clj
(ns site.build
(:require [boot.core :as boot]
[boot.pod :as pod]
[boot.util :as util]
[clojure.string :as string]
[clojure.java.io :as io]
[clojure.tools.namespace.dir :as dir]
[clojure.tools.namespace.track :as track]
[clojure.tools.namespace.reload :as reload]))
@Deraen
Deraen / test.clj
Created Jan 27, 2017
Proof of Concept, catch test output
View test.clj
(defonce ^:private log-buffer (atom nil))
(defn get-log-message []
(let [message (first @log-buffer)]
(swap! log-buffer #(vec (rest %)))
message))
(defn catch-logging [f]
(reset! log-buffer nil)
@Deraen
Deraen / closure_import_script.cljs
Created Dec 20, 2016
Queue without Core.async
View closure_import_script.cljs
(defonce reloader (atom {:deferred nil
:queue []}))
(declare maybe-load-next)
(defn ready [state next]
(next (assoc state :deferred nil)))
(defn load-next [state]
(let [[file & queue] (:queue state)
You can’t perform that action at this time.