Instantly share code, notes, and snippets.

Embed
What would you like to do?
hypercrud livecoding demo
;; Datomic uses immutability to make read queries come from in-app process instead of network.
;; Web service backed by datomic can have same performance characteristics - browser ajax read
;; queries can come from in-browser. Changes browser programming model - can code as if all data
;; is local. Removes all read-IO from browser apps. Components that do IO can now compose.
;; Still ACID & relational queries like datomic.
;;
;; Other solutions to same problem: Facebook Relay/GraphQL, Netflix Falcor, Om Next
;; This file is app code
;; Only pure functions in this file. Programming model is pure functions against local data.
(let [entry-hc-node {:href "/api?prod=true"}]
;; resolve a node in the data graph from the server.
;; In dev this is async and queries the server, and the below view-fn is invoked async.
;; In prod, the data is already local, so the view-fn is invoked synchronously, no network i/o.
[hypercrud/resolve client entry-hc-node
;; pure view fn (React.js component)
(fn [entry-hc-node]
(let [communities (-> entry-hc-node :links :communities)]
;; Arbitrarily resolve more nodes, view code access whatever nodes it wants.
;; In dev this is network i/o, in prod the data is local.
[hypercrud/resolve client communities
(fn [communities]
;; here you can see the actual view/html (React components)
[:ul
;; local data means functional transforms using the usual apis like map
(map (fn [[k community]]
;; with arbitrarily more hypercrud data resolutions
[hypercrud/resolve client community
;; and arbitrarily more sub-views
(fn [community]
[:li (-> community :data :community/name)])])
(-> communities :data))])]))])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment