Skip to content

Instantly share code, notes, and snippets.

View olivergeorge's full-sized avatar

Oliver George olivergeorge

  • Tasmania, Australia
  • 02:42 (UTC +10:00)
View GitHub Profile

Experiment to setup a single step deploy process for Datomic Ions including setting up the AWS API Gateway.

Next experiment will be generating a CloudFormation template for the app.

@olivergeorge
olivergeorge / es6-class-react.cljs
Created May 23, 2018 03:01 — forked from pesterhazy/es6-class-react.cljs
React component in pure cljs using ES6 class inheritance
;; implementing a React component in pure cljs, no reagent necessary
;; using goog.object.extend to create a ES6 class that inherits from
;; React.Component
;; credit to @thheller
(defn MyReact [props context updater]
(this-as this
(js/React.Component.call this props context updater)))
@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))