Skip to content

Instantly share code, notes, and snippets.

View olivergeorge's full-sized avatar

Oliver George olivergeorge

  • Tasmania, Australia
View GitHub Profile
@olivergeorge
olivergeorge / Type checking function body via generators.md
Last active May 14, 2018 05:48
Type checking function body via generators

Problem

Given some function specs we would like to know if there are bugs in a function definition associated with invalid function calls.

Example

(s/fdef foo :args (s/cat :x number? :y number?) :ret string?)
(s/fdef bar :args (s/cat :z coll?) :ret number?)

So what did re-natal add over the react-native template?

The shorter version is:

  • an extra node dependency
  • tweak to where the native apps look for their index file
  • a clojurescript project
  • a configuration file for re-natal

So not a lot of intrusive changes to how react-native works at all.

Navigating between scenes

React Native lets us render views but doesn't solve the problem of transitioning between scenes.

Navigation concerns include:

  • rendering common elements (headers)
  • rendering navigation elements (back button)
  • keeping track of global history stack
  • navigating between scenes

Storing data in the app

Without a persistent data store our React Native app would lose all state if killed and restarted.

React Native solves this by providing a simple storage system that is global to the app called AsyncStorage.

Tradeoffs

It is recommended that you use an abstraction on top of AsyncStorage like sunnylqm/react-native-storage but for now a few helper functions seem to suffice. Here's an alternative approach.

Effects

Storing data in the app using react-native-storage

Without a persistent data store our app would lose all state if killed and restarted.

React Native solves this by providing a simple storage system that is global to the app called AsyncStorage. It is recommended that you use an abstraction on top of AsyncStorage so we use sunnylqm/react-native-storage.

tradeoffs

We've introduced a dependency here. It's possible working directly with StorageAsync would have sufficed. See alternative approach.

I was struggling to compose datomic queries neatly. In the end I googled and found a blogpost which proposed a sane solution.

My motivation was an API endpoint with optional filters. I'd like my query include additional filters based on the args present.

Anyway, here's how my code ended up looking...

And the article: http://grishaev.me/en/datomic-query

(ns olivergeorge.schema
"generate datomic schema from simple spec forms"
(:require [clojure.spec.alpha :as s]))
(s/def ::schema-type
(s/or :db.type/string #{'string?}
:db.type/long #{'int? 'pos-int? 'neg-int? 'nat-int?}
:db.type/boolean #{'boolean?}
:db.type/float #{'float?}
:db.type/double #{'double?}
@olivergeorge
olivergeorge / dbg.cljc
Created November 8, 2017 04:55
Super simple scope capture macro for CLJS. Hoping to make it simpler.
(ns can-i-spy.dbg
(:require [clojure.spec.alpha :as s]))
(defonce dbg-meta (atom {}))
#?(:cljs (defonce dbg-data (atom {})))
(defmacro spy
[k]
(let [symbols (keys (:locals &env))
(ns can-i-stub.main
(:require [cljs.nodejs :as nodejs]
[cljs.spec.alpha :as s]
[clojure.spec.test.alpha :as stest]))
(nodejs/enable-util-print!)
(defn add2 [a b] 10.1)
(s/fdef add2 :args (s/cat :a int? :b int?) :ret int?)
@olivergeorge
olivergeorge / gist:0ee8d39896d52e7c84dabf6eb0625c9b
Last active October 4, 2017 21:54
deps tree differences relating to tools-reader

Couple of extracts from lein deps :tree

With

:dependencies [[com.taoensso/encore "2.92.0"]
                 [org.clojure/clojurescript "1.9.946"]]
[com.taoensso/encore "2.92.0"]