Skip to content

Instantly share code, notes, and snippets.

View swannodette's full-sized avatar

David Nolen swannodette

View GitHub Profile
(ns async-test.core
(:require-macros [cljs.core.async.macros :as async])
(:require [cljs.core.async :as async]))
(enable-console-print!)
(defn looper [ch handler-fn]
(async/go-loop []
(handler-fn (async/<! ch))
(recur)))
@swannodette
swannodette / inference.md
Last active August 7, 2023 16:13
Externs Inference

Externs Inference

Integrating third party JavaScript libraries not written with Google Closure Compiler in mind continues to both be a source of error for users when going to production, and significant vigilance and effort for the the broader community (CLJSJS libraries must provide up-to-date and accurate externs).

In truth writing externs is far simpler than most users imagine. You only need externs for the parts of the library you actually intend to use from ClojureScript. However this isn't so easy to determine from Closure's own documentation. Still in the process of writing your code it's easy to miss a case. In production you will see the much dreaded error that some mangled name does not exist. Fortunately it's possible to enable some compiler flags :pretty-print true :pseudo-names true to generate an advanced build with human readable names. However debugging missing externs means compiling your production build for each missed case. So much time wasted for such simple mistakes damages our sen

(require 'tubular.core)
(tubular.core/connect "127.0.0.1" REPL_PORT)
(ns om.next.spec
(:require [cljs.spec :as s]
[clojure.test.check :as tc]
[clojure.test.check.properties :as tcp]))
(s/def ::statics
(s/cat
:static '#{static}
:protocol-name '#{om.next/Ident om.next/IQuery om.next/IQueryParams}
:impls (s/* seq?)))
@swannodette
swannodette / spec.cljs
Last active March 5, 2018 23:24
om.next query spec
(ns om.next.spec
(:require [cljs.spec :as s]))
(s/def ::ident (s/and vector? (s/cat :ident keyword? :value #(not (coll? %)))))
(s/def ::join-key (s/or :prop keyword? :ident ::ident))
(s/def ::join (s/and (s/map-of ::join-key ::query) #(= (count %) 1)))
(s/def ::union (s/and (s/map-of keyword? ::query) #(> (count %) 1)))
(s/def ::param-expr
(s/cat :query-expr ::query-expr
(ns socket-repl-test.core
(:require [cljs.repl :as repl]
[cljs.repl.node :as node]
[clojure.core.server :as server]))
(defn node-repl []
(repl/repl (node/repl-env)))
(defn cljs-repl-server []
(server/start-server
var ArrayList = Packages.java.util.ArrayList,
File = Packages.java.io.File,
jscomp = Packages.com.google.javascript.jscomp,
SourceFile = jscomp.SourceFile,
BasicErrorManager = jscomp.BasicErrorManager,
DepsGenerator = jscomp.deps.DepsGenerator,
InclusionStrategy = DepsGenerator.InclusionStrategy;
function jsFilesInDir(dir) {
var ret = new ArrayList(),
(defn my-get
"@param {*} m
@param {*} k
@return {nil|Object}"
[m k]
(get m k))
(defn foo
"@param {!Object} x" ;; non-nullable
[x] x)
;; 1 - The var associated to a def, (def my-var ...) - L1142
(DefExpr. :def env form var-name
;; TODO: check if this map should be a VarExpr - Sebastian
(assoc (analyze (-> env (dissoc :locals)
(assoc :context :expr)
(assoc :def-var true))
sym)
:op :var)
doc (:jsdoc sym-meta) init-expr
@swannodette
swannodette / reactpersist.md
Created May 28, 2015 19:17 — forked from chenglou/gist:34b155691a6f58091953
Persistent React Component Problem

key is pretty much crucial for state perservation in React. As of React 0.13 it can't do the following things:

  • Clone state
<Comp key={1} /><Comp key={1} />
  • Preserve component state across different parents: