Skip to content

Instantly share code, notes, and snippets.

(ns datascript-diff
(:require [datascript.core :as d]
[datascript.btset :as btset]))
(defn- keys-eq? [a b]
(or (identical? (.-keys a) (.-keys b))
(let [achunk (btset/iter-chunk a)
bchunk (btset/iter-chunk b)]
(and (== (count achunk) (count bchunk))
@seantempesta
seantempesta / reagent.cljs
Created May 10, 2017 07:11
cljs-react-navigation.reagent
(ns cljs-react-navigation.reagent
(:require [cljs-react-navigation.base :as base]
[reagent.core :as r]
[reagent.impl.component :as ric]
[cljs.spec :as s :include-macros true]
[cljs.spec.test :as stest :include-macros true]
[cljs.spec.impl.gen :as gen]
[oops.core :refer [oget oget+ oset! ocall oapply ocall! oapply!]]
[taoensso.timbre :refer-macros [log trace debug info warn error]]))
@seantempesta
seantempesta / base.cljs
Created May 10, 2017 07:10
cljs-react-navigation.base
(ns cljs-react-navigation.base
(:require [reagent.core :as r]
[reagent.impl.component :as ric]
[cljs.spec :as s :include-macros true]
[cljs.spec.test :as stest :include-macros true]
[cljs.spec.impl.gen :as gen]
[taoensso.timbre :refer-macros [log trace debug info warn error]]
[oops.core :refer [oget oset! ocall oapply ocall! oapply!]]))
(defonce React (js/require "react"))
(defn virtualized-list
"Reagent version of VirtualizedList
https://facebook.github.io/react-native/releases/0.43/docs/virtualizedlist.html
props = Map with at least :data and :renderItem specified
:data = A vector (or list I suppose) with whatever you want passed to each row
:renderItem = A fn that accepts a map with two keys {:item row-data, :index row-number} and returns a reagent vector.
Ex. [virtualized-list {:data [{:a 1} {:a 2}]
:renderItem (fn [{:keys [item index]}]
@seantempesta
seantempesta / update.clj
Created February 15, 2017 03:36
Datomic update for user info from form data
(defn user-info
"Updates a user entity with form-data supplied by the user.
Steps:
1. Validate the data.
2. Ensure that I'm only updating certain keys. (since spec allows extra keys)
3. Create a merged map to update the entity. (this feels hacky!)
4. Create an audit map.
5. Transact and return success."
[conn form-data user]
(if (s/valid? :user/info form-data)
(def sample-data '(#datascript/Datom [1 :attendance/checkInTime "2016-07-08T08:27:50.778Z" "536870913" true] #datascript/Datom [1 :attendance/group 16 "536870913" true] #datascript/Datom [1 :attendance/participant 17 "536870913" true] #datascript/Datom [2 :group/absentAfterMinutes 15 "536870913" true] #datascript/Datom [2 :group/endTimeHour 2 "536870913" true] #datascript/Datom [2 :group/endTimeMinute 51 "536870913" true] #datascript/Datom [2 :group/latePickupAfterMinutes 15 "536870913" true] #datascript/Datom [2 :group/name "Group 1" "536870913" true] #datascript/Datom [2 :group/participants 3 "536870913" true] #datascript/Datom [2 :group/participants 8 "536870913" true] #datascript/Datom [2 :group/participants 38 "536870913" true] #datascript/Datom [2 :group/participants 45 "536870913" true] #datascript/Datom [2 :group/participants 58 "536870913" true] #datascript/Datom [2 :group/startTimeHour 1 "536870913" true] #datascript/Datom [2 :group/startTimeMinute 51 "536870913" true] #datascript/Datom [3 :partici
@seantempesta
seantempesta / routing.cljs
Created April 11, 2016 16:52
An example of using react-native-router-flux with reagent
(defstate ReactNativeRouterFlux :start (js/require "react-native-router-flux"))
(defstate TabBar :start (.-TabBar @ReactNativeRouterFlux))
(defstate Actions :start (.-Actions @ReactNativeRouterFlux))
(defstate Modal :start (.-Modal @ReactNativeRouterFlux))
(defstate Reducer :start (.-Reducer @ReactNativeRouterFlux))
(defstate router :start (r/adapt-react-class (.-Router @ReactNativeRouterFlux)))
(defstate scene :start (r/adapt-react-class (.-Scene @ReactNativeRouterFlux)))
(defn reducerCreate [params]
(let [defaultReducer (@Reducer params)]
@seantempesta
seantempesta / core.cljs
Created February 1, 2016 18:37
om-next + react-native
(ns mattsum.simple-example.core
(:require-macros [natal-shell.core :refer [with-error-view]]
[natal-shell.components :refer [view text image touchable-highlight]]
[natal-shell.alert :refer [alert]])
(:require [om.next :as om :refer-macros [defui]]))
(set! js/React (js/require "react-native/Libraries/react-native/react-native.js"))
(def app-registry
(.-AppRegistry js/React))