Skip to content

Instantly share code, notes, and snippets.

(ns navigation.example
(:require-macros [natal-shell.components :refer [navigator]]
[navigation.macros :refer [with-om-vars]])
(:require [om.next :as om]))
;;; Helpers for getting a deep ref
(defn react-ref
"Wrapper around react-ref to always turn keywords into strings."
[component ref]
@petterik
petterik / macro-fail.clj
Created March 24, 2016 13:39
Calling a declared macro results in "wrong number of args (-1)"
(declare fail)
(defn fail* [m]
(if (map? m)
(fail 1)
m))
(defmacro fail [m]
(if (map? m)
(fail* m)
;; This is a stand alone version of https://github.com/petterik/om/commit/c99f1b892f0a143fba6ce57c3ffefc7ce1e2b9a0
;; Changed so that in path-meta, we're parsing the joins from a query one time for each data collection
;; instead of parsing joins for each item in the collection.
;; This gist contains implementation and a test.
;; It's runnable with planck by either downloading the gist as gist.cljs and passing it to planck
;; with the om source code:
;; planck -c "<path-to-om-project>/src/main" gist.cljs
(ns petterik.path-meta-perf
diff --git a/src/main/om/next.cljc b/src/main/om/next.cljc
index ff19d99..3ea9682 100644
--- a/src/main/om/next.cljc
+++ b/src/main/om/next.cljc
@@ -2517,10 +2517,10 @@
root (:root @state)]
#?(:cljs
(doseq [c ((:optimize config) cs)]
- (let [props-change? (> (p/basis-t this) (t c))]
+ (let [props-change? (and (iquery? c) (> (p/basis-t this) (t c)))]
;; Here are 4 different versions of the sieve function with slight changes to test my theories
;; around seq, chunked-seq and transducer (reduce) api.
;; Try running these yourself with: (run-all)
(declare sieves)
(defn run-all []
(doseq [[k sieve] sieves]
(prn "Running:" k)
(dotimes [_ 5]
(time (sieve 10000)))))
(require '[datascript.btset :as btset])
(require '[datascript.arrays :as da])
;; What?
;; Fast equality check for btset/Iter
;;
;; Why?
;; There's no history or (d/since ) API and I want to know what's changed between two databases.
;; With fast Iter equality checks, I can quickly check if an attribute has changed between
;; my two database values like so:
(defn join [{:keys [parser query target] :as env} k _]
(let [ret (parser env query target)]
(if target
(when (seq ret)
{target (assoc ast :query ret)})
{:value ret})))
@petterik
petterik / om-ui-with-locals.clj
Last active May 4, 2017 14:11
om-ui with defs for specified locals
(defmacro with-defs
"Takes a seq of symbols which will be called with def for generated symbols.
These symbols will be replaced in the body with the generated symbols
Examples:
(let [a 1] (macroexpand '(with-defs [a] [a]))) ;; => (do (def a_60267 a) [a_60267])
(let [a 1] (with-defs [a] [a])) ;; => [1]"
[vars & body]
{:pre [(every? symbol? vars)]}
(let [syms (into {} (map (juxt identity #(gensym (str (name %) "_")))) vars)
@petterik
petterik / transform-reads-missing-reads.clj
Created May 17, 2017 19:45
om.next transform-reads issue
;; Issue with om/transform-reads
;; Issue is when having two siblings or cousins with the same read-key
;; in nested at level 2 or deeper, transform-reads will two paths
;; with the same root. Parsing such query will overwrite the first path
;; returning only the second one.
;; Example:
;; (om/transform-reads r [:foo])
;; returns: [#:join{:parent [#:join{:child1 [:foo]}]}
;; #:join{:parent [#:join{:child2 [:foo]}]}]
@petterik
petterik / inf-compile-cljs.loader.cljs
Created July 3, 2017 19:05
jstack calls to clojurescript compiler's pid when compiling cljs.loader.cljs takes forever forever
Did:
- Built optimizations :advanced, clojurescript 1.9.683 with cljs.loader
Happened:
- Compilation ran forever. Last output being:
`Compiling resources/public/release/js/out/cljs/loader.cljs`
Debug:
- Ran 5 times:
`jstack 54630 >> cljs-loader-compile.stack`