-
-
Save poppingtonic/11309357 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns om-data.core | |
(:require [om.core :as om :include-macros true] | |
[om.dom :as dom :include-macros true] | |
[datascript :as d])) | |
(enable-console-print!) | |
(def schema {}) | |
(def conn (d/create-conn schema)) | |
;; prevent cursor-ification | |
(extend-type d/DB | |
om/IToCursor | |
(-to-cursor | |
([this _] this) | |
([this _ _] this))) | |
(d/transact! conn | |
[{:db/id -1 | |
:title "Hello world!" | |
:count 0}]) | |
(defn get-conn [owner] | |
(om/get-shared owner :conn)) | |
(defn app-title [db] | |
(ffirst | |
(d/q | |
'[:find ?title | |
:where | |
[?e :title ?title]] | |
db))) | |
(defn app-count [db] | |
(ffirst | |
(d/q | |
'[:find ?count | |
:where | |
[?e :count ?count]] | |
db))) | |
(defn app-view [db owner] | |
(reify | |
om/IRender | |
(render [_] | |
(let [count (app-count db)] | |
(dom/div nil | |
(dom/h2 nil (app-title db)) | |
(dom/div nil | |
(dom/span nil count) | |
(dom/button | |
#js {:style #js {:marginLeft "5px"} | |
:onClick | |
(fn [e] | |
(d/transact! (get-conn owner) | |
[[:db/add 1 :count (inc count)]]) | |
(om/refresh! owner))} | |
"+"))))))) | |
(om/root app-view conn | |
{:shared {:conn conn} | |
:target (. js/document (getElementById "app"))}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment