├── .gitignore
├── .gitmodules
├── LICENSE
├── README.md
├── doc
└── intro.md
├── env
├── dev
│ └── cljs
│ │ └── datodomvc
│ │ └── client
│ │ ├── debug.cljs
│ │ └── dev.cljs
└── production
│ └── cljs
│ └── datodomvc
│ └── client
│ └── productions.cljs
├── profiles.clj
├── project.clj
├── resources
└── public
│ └── css
│ ├── base.css
│ └── index.css
├── src
├── cljs
│ └── datodomvc
│ │ └── client
│ │ ├── components
│ │ └── root.cljs
│ │ ├── config.cljs
│ │ ├── core.cljs
│ │ ├── routes.cljs
│ │ └── utils.cljs
├── datodomvc
│ ├── config.clj
│ ├── core.clj
│ ├── datomic
│ │ ├── core.clj
│ │ ├── migrations.clj
│ │ └── schema.clj
│ ├── init.clj
│ ├── nrepl.clj
│ └── server.clj
└── shared
│ └── .gitkeep
└── test
└── datodomvc
└── core_test.clj
/.gitignore:
--------------------------------------------------------------------------------
1 | /target
2 | /classes
3 | /checkouts
4 | pom.xml
5 | pom.xml.asc
6 | *.jar
7 | *.class
8 | /.lein-*
9 | /.nrepl-port
10 | .hgignore
11 | .hg/
12 | resources/public/js/bin*
13 | figwheel_server.log
14 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "vendor/datascript"]
2 | path = vendor/datascript
3 | url = git@github.com:sgrove/datascript.git
4 | [submodule "vendor/dato"]
5 | path = vendor/dato
6 | url = git@github.com:sgrove/dato.git
7 | [submodule "vendor/garden"]
8 | path = vendor/garden
9 | url = git@github.com:sgrove/garden.git
10 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC
2 | LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM
3 | CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
4 |
5 | 1. DEFINITIONS
6 |
7 | "Contribution" means:
8 |
9 | a) in the case of the initial Contributor, the initial code and
10 | documentation distributed under this Agreement, and
11 |
12 | b) in the case of each subsequent Contributor:
13 |
14 | i) changes to the Program, and
15 |
16 | ii) additions to the Program;
17 |
18 | where such changes and/or additions to the Program originate from and are
19 | distributed by that particular Contributor. A Contribution 'originates' from
20 | a Contributor if it was added to the Program by such Contributor itself or
21 | anyone acting on such Contributor's behalf. Contributions do not include
22 | additions to the Program which: (i) are separate modules of software
23 | distributed in conjunction with the Program under their own license
24 | agreement, and (ii) are not derivative works of the Program.
25 |
26 | "Contributor" means any person or entity that distributes the Program.
27 |
28 | "Licensed Patents" mean patent claims licensable by a Contributor which are
29 | necessarily infringed by the use or sale of its Contribution alone or when
30 | combined with the Program.
31 |
32 | "Program" means the Contributions distributed in accordance with this
33 | Agreement.
34 |
35 | "Recipient" means anyone who receives the Program under this Agreement,
36 | including all Contributors.
37 |
38 | 2. GRANT OF RIGHTS
39 |
40 | a) Subject to the terms of this Agreement, each Contributor hereby grants
41 | Recipient a non-exclusive, worldwide, royalty-free copyright license to
42 | reproduce, prepare derivative works of, publicly display, publicly perform,
43 | distribute and sublicense the Contribution of such Contributor, if any, and
44 | such derivative works, in source code and object code form.
45 |
46 | b) Subject to the terms of this Agreement, each Contributor hereby grants
47 | Recipient a non-exclusive, worldwide, royalty-free patent license under
48 | Licensed Patents to make, use, sell, offer to sell, import and otherwise
49 | transfer the Contribution of such Contributor, if any, in source code and
50 | object code form. This patent license shall apply to the combination of the
51 | Contribution and the Program if, at the time the Contribution is added by the
52 | Contributor, such addition of the Contribution causes such combination to be
53 | covered by the Licensed Patents. The patent license shall not apply to any
54 | other combinations which include the Contribution. No hardware per se is
55 | licensed hereunder.
56 |
57 | c) Recipient understands that although each Contributor grants the licenses
58 | to its Contributions set forth herein, no assurances are provided by any
59 | Contributor that the Program does not infringe the patent or other
60 | intellectual property rights of any other entity. Each Contributor disclaims
61 | any liability to Recipient for claims brought by any other entity based on
62 | infringement of intellectual property rights or otherwise. As a condition to
63 | exercising the rights and licenses granted hereunder, each Recipient hereby
64 | assumes sole responsibility to secure any other intellectual property rights
65 | needed, if any. For example, if a third party patent license is required to
66 | allow Recipient to distribute the Program, it is Recipient's responsibility
67 | to acquire that license before distributing the Program.
68 |
69 | d) Each Contributor represents that to its knowledge it has sufficient
70 | copyright rights in its Contribution, if any, to grant the copyright license
71 | set forth in this Agreement.
72 |
73 | 3. REQUIREMENTS
74 |
75 | A Contributor may choose to distribute the Program in object code form under
76 | its own license agreement, provided that:
77 |
78 | a) it complies with the terms and conditions of this Agreement; and
79 |
80 | b) its license agreement:
81 |
82 | i) effectively disclaims on behalf of all Contributors all warranties and
83 | conditions, express and implied, including warranties or conditions of title
84 | and non-infringement, and implied warranties or conditions of merchantability
85 | and fitness for a particular purpose;
86 |
87 | ii) effectively excludes on behalf of all Contributors all liability for
88 | damages, including direct, indirect, special, incidental and consequential
89 | damages, such as lost profits;
90 |
91 | iii) states that any provisions which differ from this Agreement are offered
92 | by that Contributor alone and not by any other party; and
93 |
94 | iv) states that source code for the Program is available from such
95 | Contributor, and informs licensees how to obtain it in a reasonable manner on
96 | or through a medium customarily used for software exchange.
97 |
98 | When the Program is made available in source code form:
99 |
100 | a) it must be made available under this Agreement; and
101 |
102 | b) a copy of this Agreement must be included with each copy of the Program.
103 |
104 | Contributors may not remove or alter any copyright notices contained within
105 | the Program.
106 |
107 | Each Contributor must identify itself as the originator of its Contribution,
108 | if any, in a manner that reasonably allows subsequent Recipients to identify
109 | the originator of the Contribution.
110 |
111 | 4. COMMERCIAL DISTRIBUTION
112 |
113 | Commercial distributors of software may accept certain responsibilities with
114 | respect to end users, business partners and the like. While this license is
115 | intended to facilitate the commercial use of the Program, the Contributor who
116 | includes the Program in a commercial product offering should do so in a
117 | manner which does not create potential liability for other Contributors.
118 | Therefore, if a Contributor includes the Program in a commercial product
119 | offering, such Contributor ("Commercial Contributor") hereby agrees to defend
120 | and indemnify every other Contributor ("Indemnified Contributor") against any
121 | losses, damages and costs (collectively "Losses") arising from claims,
122 | lawsuits and other legal actions brought by a third party against the
123 | Indemnified Contributor to the extent caused by the acts or omissions of such
124 | Commercial Contributor in connection with its distribution of the Program in
125 | a commercial product offering. The obligations in this section do not apply
126 | to any claims or Losses relating to any actual or alleged intellectual
127 | property infringement. In order to qualify, an Indemnified Contributor must:
128 | a) promptly notify the Commercial Contributor in writing of such claim, and
129 | b) allow the Commercial Contributor tocontrol, and cooperate with the
130 | Commercial Contributor in, the defense and any related settlement
131 | negotiations. The Indemnified Contributor may participate in any such claim
132 | at its own expense.
133 |
134 | For example, a Contributor might include the Program in a commercial product
135 | offering, Product X. That Contributor is then a Commercial Contributor. If
136 | that Commercial Contributor then makes performance claims, or offers
137 | warranties related to Product X, those performance claims and warranties are
138 | such Commercial Contributor's responsibility alone. Under this section, the
139 | Commercial Contributor would have to defend claims against the other
140 | Contributors related to those performance claims and warranties, and if a
141 | court requires any other Contributor to pay any damages as a result, the
142 | Commercial Contributor must pay those damages.
143 |
144 | 5. NO WARRANTY
145 |
146 | EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON
147 | AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER
148 | EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR
149 | CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A
150 | PARTICULAR PURPOSE. Each Recipient is solely responsible for determining the
151 | appropriateness of using and distributing the Program and assumes all risks
152 | associated with its exercise of rights under this Agreement , including but
153 | not limited to the risks and costs of program errors, compliance with
154 | applicable laws, damage to or loss of data, programs or equipment, and
155 | unavailability or interruption of operations.
156 |
157 | 6. DISCLAIMER OF LIABILITY
158 |
159 | EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY
160 | CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL,
161 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION
162 | LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
163 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
164 | ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE
165 | EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY
166 | OF SUCH DAMAGES.
167 |
168 | 7. GENERAL
169 |
170 | If any provision of this Agreement is invalid or unenforceable under
171 | applicable law, it shall not affect the validity or enforceability of the
172 | remainder of the terms of this Agreement, and without further action by the
173 | parties hereto, such provision shall be reformed to the minimum extent
174 | necessary to make such provision valid and enforceable.
175 |
176 | If Recipient institutes patent litigation against any entity (including a
177 | cross-claim or counterclaim in a lawsuit) alleging that the Program itself
178 | (excluding combinations of the Program with other software or hardware)
179 | infringes such Recipient's patent(s), then such Recipient's rights granted
180 | under Section 2(b) shall terminate as of the date such litigation is filed.
181 |
182 | All Recipient's rights under this Agreement shall terminate if it fails to
183 | comply with any of the material terms or conditions of this Agreement and
184 | does not cure such failure in a reasonable period of time after becoming
185 | aware of such noncompliance. If all Recipient's rights under this Agreement
186 | terminate, Recipient agrees to cease use and distribution of the Program as
187 | soon as reasonably practicable. However, Recipient's obligations under this
188 | Agreement and any licenses granted by Recipient relating to the Program shall
189 | continue and survive.
190 |
191 | Everyone is permitted to copy and distribute copies of this Agreement, but in
192 | order to avoid inconsistency the Agreement is copyrighted and may only be
193 | modified in the following manner. The Agreement Steward reserves the right to
194 | publish new versions (including revisions) of this Agreement from time to
195 | time. No one other than the Agreement Steward has the right to modify this
196 | Agreement. The Eclipse Foundation is the initial Agreement Steward. The
197 | Eclipse Foundation may assign the responsibility to serve as the Agreement
198 | Steward to a suitable separate entity. Each new version of the Agreement will
199 | be given a distinguishing version number. The Program (including
200 | Contributions) may always be distributed subject to the version of the
201 | Agreement under which it was received. In addition, after a new version of
202 | the Agreement is published, Contributor may elect to distribute the Program
203 | (including its Contributions) under the new version. Except as expressly
204 | stated in Sections 2(a) and 2(b) above, Recipient receives no rights or
205 | licenses to the intellectual property of any Contributor under this
206 | Agreement, whether expressly, by implication, estoppel or otherwise. All
207 | rights in the Program not expressly granted under this Agreement are
208 | reserved.
209 |
210 | This Agreement is governed by the laws of the State of New York and the
211 | intellectual property laws of the United States of America. No party to this
212 | Agreement will bring a legal action under this Agreement more than one year
213 | after the cause of action arose. Each party waives its rights to a jury trial
214 | in any resulting litigation.
215 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # DatodoMVC
2 |
3 | A [TodoMVC](http://todomvc.com/) implementation using [Dato](https://github.com/sgrove/dato), the Clojure/Script Datomic/DataScipt app development framework.
4 |
5 | This is an implementation of TodoMVC using Datomic on the backend to persist data that's then fed to DataScript in the frontend. The UI is driven entirely from the DataScript DB (even component local state). See the [Dato Rationale](https://github.com/sgrove/dato#rationale) for more. [Here's a video](https://www.youtube.com/watch?v=7bAdBXfZtZU) of what it looks like once it's running
6 |
7 | ## Running this demo
8 |
9 | 1. Install and start Datomic (TODO: friendlier instructions here)
10 |
11 | 2. Clone this repo
12 |
13 | ```
14 | git clone git@github.com:sgrove/datodomvc.git
15 | cd datodomvc
16 | git submodule update --init
17 | ```
18 |
19 | 3. Start the figwheel server. Figwheel compiles the frontend assets, recompiles them when the files change, and updates the browser with the changed code.
20 |
21 | `lein figwheel` or `rlwrap lein figwheel`
22 |
23 | 4. Start the web server. Export a few environment variables to get things working on your system. The DatodoMVC example uses environ, so you can also define env variables in a local profiles.clj.
24 |
25 | ```
26 | export DATOMIC_URI="datomic:free://localhost:4334/pc2" # This will depend on your datomic setup
27 | export NREPL_PORT=6005 # starts embedded nrepl server
28 | export DATO_PORT=8081 # 8080 is the default value, change it if there is a port conflict
29 | export PORT=10556 # 10555 is the default
30 | lein run
31 | ```
32 |
33 | ## Support
34 |
35 | * For questions on getting this demo running or modifying it, feel free to open issues on this repo.
36 | * For overall Dato design issues, please use the [Dato Repo's issue tracker](https://github.com/sgrove/dato/issues)
37 | * General questions, I'm on twitter at [@sgrove](https://twitter.com/sgrove)
38 |
39 | ## License
40 |
41 | Copyright © 2015 Sean Grove
42 |
43 | Distributed under the Eclipse Public License either version 1.0 or (at
44 | your option) any later version.
45 |
--------------------------------------------------------------------------------
/doc/intro.md:
--------------------------------------------------------------------------------
1 | # Introduction to datodomvc
2 |
3 | TODO: write [great documentation](http://jacobian.org/writing/what-to-write/)
4 |
--------------------------------------------------------------------------------
/env/dev/cljs/datodomvc/client/debug.cljs:
--------------------------------------------------------------------------------
1 | (ns datodomvc.client.debug
2 | (:require [datascript :as d]
3 | [dato.lib.core :as dato]
4 | [dato.db.utils :as dsu]))
5 |
6 | (def watched-expressions
7 | [{:title "Local session"
8 | :fn (fn [db] (let [local-session-ptrs (dsu/qes-by db :local/current-session)
9 | sessions (map (comp dsu/t :local/current-session) local-session-ptrs)]
10 | {:local-session-ptrs local-session-ptrs
11 | :sessions sessions
12 | :dato-session (when-let [s (dato/local-session db)]
13 | (dsu/t s))}))}])
14 |
--------------------------------------------------------------------------------
/env/dev/cljs/datodomvc/client/dev.cljs:
--------------------------------------------------------------------------------
1 | (ns ^:figwheel-always datodomvc.client.dev
2 | (:require [dato.debug.components.core :as dato-debug]
3 | [devtools.core :as devtools]
4 | [figwheel.client :as figwheel :include-macros true]
5 | [datodomvc.client.core :as datodomvc-core]
6 | [datodomvc.client.debug :as todo-debug]
7 | [datodomvc.client.utils :as utils]
8 | [om.core :as om]
9 | [om-i.core :as om-i]
10 | [om-i.hacks :as om-i-hacks]
11 | [weasel.repl :as weasel]))
12 |
13 | (defn dev-connect! []
14 | #_(figwheel/watch-and-reload
15 | :websocket-url "ws://localhost:3449/figwheel-ws"
16 | :jsload-callback (fn [] (js/console.log "Reloading from figwheel..")))
17 | (when (:weasel? utils/initial-query-map)
18 | (weasel/connect "ws://localhost:9001" :verbose true :print #{:repl :console}))
19 | true)
20 |
21 | (defonce setup-misc
22 | (do
23 | (dev-connect!)
24 | (om-i-hacks/insert-styles)
25 | (om-i/setup-component-stats!)
26 | ;; Enable https://github.com/binaryage/cljs-devtools
27 | (js/console.log "Installing devtools...")
28 | (devtools/install!)
29 | (js/console.log "Loading DatodoMVC via dev..." utils/initial-query-map)))
30 |
31 | (defn -main []
32 | (let [root-node (js/document.getElementById "datodomvc-app")
33 | app-state datodomvc-core/app-state
34 | dato (:dato @app-state)
35 | app-root (datodomvc-core/-main root-node
36 | app-state
37 | {:om-instrument (fn [f cursor m]
38 | (let [com (satisfies? om/IDisplayName (f))])
39 | (om/build* f cursor
40 | (if (:descriptor m)
41 | m
42 | (assoc m :descriptor
43 | dato-debug/watch-state-methods
44 | ;; TODO: Figure out how to compose these
45 | ;; om-i/instrumentation-methods
46 | ))))})]
47 | (om/root dato-debug/devtools {:dato dato}
48 | {:target (utils/sel1 root-node :.debugger-container)
49 | :shared {:dato dato
50 | :app-root app-root}
51 | :opts {:expressions todo-debug/watched-expressions}})))
52 |
53 | (-main)
54 |
--------------------------------------------------------------------------------
/env/production/cljs/datodomvc/client/productions.cljs:
--------------------------------------------------------------------------------
1 | (ns datodomvc.client.productions
2 | (:require [datodomvc.client.core :as datodomvc-core]
3 | [datodomvc.client.utils :as utils]))
4 |
5 | (js/console.log "Loading DatodoMVC via production..." (pr-str utils/initial-query-map))
6 |
7 | (defn -main []
8 | (datodomvc-core/-main (js/document.getElementById "datodomvc-app") datodomvc-core/app-state))
9 |
10 | (-main)
11 |
--------------------------------------------------------------------------------
/profiles.clj:
--------------------------------------------------------------------------------
1 | {:dev {:source-paths ["env/dev/cljs/" "src/cljs" "env/dev/clj"]
2 |
3 | :plugins [[cider/cider-nrepl "0.9.1" :exclusions [org.clojure/tools.nrepl]]
4 | [lein-ancient "0.6.7" :exclusions [org.clojure/clojure]]
5 | [lein-figwheel "0.3.9-SNAPSHOT" :exclusions [org.clojure/clojure org.codehaus.plexus/plexus-utils compojure commons-codec org.clojure/tools.reader org.clojure/clojurescript]]
6 | [refactor-nrepl "1.0.5" :exclusions [org.clojure/clojure org.clojure/tools.nrepl]]]
7 |
8 | :dependencies [[com.cemerick/piggieback "0.2.1" :exclusions [org.clojure/clojure org.clojure/clojurescript org.clojure/tools.nrepl]]
9 | [figwheel-sidecar "0.3.9-SNAPSHOT" :exclusions [org.clojure/clojure org.codehaus.plexus/plexus-utils compojure commons-codec org.clojure/tools.reader org.clojure/clojurescript]]
10 | [org.clojure/tools.nrepl "0.2.10"]
11 | [weasel "0.7.0" :exclusions [http-kit org.clojure/clojurescript]]]
12 |
13 | :repl-options {:init-ns datodomvc.server
14 | :nrepl-middleware [cemerick.piggieback/wrap-cljs-repl]}
15 |
16 | :test-paths ["test/clj"]
17 |
18 | :env {:is-dev true}}
19 |
20 | :uberjar {:source-paths ["env/production/clj" "env/dev/cljs/"]
21 | :prep-tasks ["compile" ["cljsbuild" "once"]]
22 | :env {:is-dev false}
23 | :omit-source true
24 | :aot :all
25 | :plugins [[cider/cider-nrepl "0.9.1" :exclusions [org.clojure/tools.nrepl]]
26 | [lein-ancient "0.6.7" :exclusions [org.clojure/clojure]]
27 | [refactor-nrepl "1.0.5" :exclusions [org.clojure/clojure org.clojure/tools.nrepl]]]
28 |
29 | :dependencies [[org.clojure/tools.nrepl "0.2.10"]]
30 | :cljsbuild {:builds [{:app
31 | {:source-paths ["env/production/cljs"]
32 | :compiler
33 | {:optimizations :advanced
34 | :pretty-print false}}}]}}}
35 |
--------------------------------------------------------------------------------
/project.clj:
--------------------------------------------------------------------------------
1 | (defproject datodomvc "0.1.0-SNAPSHOT"
2 | ;; See profiles.clj for profiles
3 | :description "FIXME: write description"
4 | :url ""
5 |
6 | :license {:name "Eclipse Public License"
7 | :url "http://www.eclipse.org/legal/epl-v10.html"}
8 |
9 | :repositories {"my.datomic.com" {:url "https://my.datomic.com/repo"
10 | :creds :gpg}}
11 | :plugins [[lein-cljsbuild "1.0.6" :exclusions [org.clojure/clojurescript]]
12 | [lein-environ "1.0.0"]
13 | [lein-less "1.7.5"]
14 | [lein-figwheel "0.3.9"]]
15 |
16 | :less {:source-paths ["src/main/less"]
17 | :target-path "target/public/css"}
18 |
19 | :exclusions [[org.clojure/clojure]
20 | [org.clojure/clojurescript]
21 | org.clojure/clojurescript org.clojure/clojure]
22 |
23 | :dependencies [[bidi "1.21.0" :exclusions [ring/ring-core]]
24 | ;; Chrome extension for cljs dev
25 | [binaryage/devtools "0.3.0"]
26 | [bk/ring-gzip "0.1.1"]
27 | [cheshire "5.5.0" :exclusions [org.clojure/clojure org.clojure/clojurescript com.fasterxml.jackson.core/jackson-core]]
28 | [cljsjs/codemirror "5.6.0-0"]
29 | [cljsjs/react "0.12.2-8"]
30 | [clojurewerkz/scrypt "1.2.0"]
31 | [com.cognitect/transit-clj "0.8.275" :exclusions [com.fasterxml.jackson.core/jackson-core]]
32 | [com.cognitect/transit-cljs "0.8.225" :exclusions [org.clojure/clojurescript]]
33 | [com.datomic/datomic-pro "0.9.5206" :exclusions [org.slf4j/slf4j-nop joda-time org.slf4j/slf4j-api org.clojure/clojurescript]]
34 | [com.fasterxml.jackson.core/jackson-annotations "2.3.1"]
35 | [com.fasterxml.jackson.core/jackson-core "2.3.1"]
36 | [compojure "1.3.1"]
37 | ;;[datascript "0.11.6"]
38 | [environ "1.0.0"]
39 | [garden "1.3.0-SNAPSHOT"]
40 | [hiccup "1.0.5"]
41 | [instaparse "1.4.0"]
42 | [javax.servlet/servlet-api "2.5"]
43 | [kibu/pushy "0.3.3"]
44 | [org.bouncycastle/bcmail-jdk15on "1.52"]
45 | [org.bouncycastle/bcprov-jdk15on "1.52"]
46 | [org.clojure/clojure "1.7.0"]
47 | [org.clojure/clojurescript "1.7.122" :exclusions [org.clojure/clojure org.clojure/tools.reader org.clojure/clojurescript
48 | org.clojure/google-closure-library-third-party]]
49 | [org.clojure/core.async "0.1.346.0-17112a-alpha"]
50 | [org.clojure/data.json "0.2.6" :classifier "aot"]
51 | [org.clojure/google-closure-library "0.0-20150805-acd8b553" :exclusions [org.clojure/google-closure-library-third-party org.clojure/clojure org.clojure/clojurescript]]
52 | [org.clojure/google-closure-library-third-party "0.0-20150505-021ed5b3"]
53 | [org.clojure/test.check "0.7.0"]
54 | [org.clojure/tools.logging "0.2.6"]
55 | [org.clojure/tools.reader "0.10.0-alpha3"]
56 | [org.eclipse.jetty/jetty-util "9.2.12.v20150709"]
57 | [org.immutant/immutant "2.0.1" :exclusions
58 | [org.hornetq/hornetq-native org.jboss.logging/jboss-logging org.jgroups/jgroups org.clojure/clojure org.hornetq/hornetq-commons org.clojure/tools.reader org.hornetq/hornetq-server org.slf4j/slf4j-api org.hornetq/hornetq-core-client org.clojure/clojurescript org.hornetq/hornetq-journal]]
59 | [org.immutant/immutant-transit "0.2.2" :exclusions [org.clojure/clojure org.clojure/clojurescript com.fasterxml.jackson.core/jackson-core org.clojure/clojure org.clojure/tools.reader org.slf4j/slf4j-api org.clojure/clojurescript org.hornetq/hornetq-server]]
60 | [org.omcljs/om "0.8.8"]
61 | [org.postgresql/postgresql "9.3-1102-jdbc41"]
62 | [org.slf4j/slf4j-api "1.6.2"]
63 | [org.slf4j/slf4j-log4j12 "1.6.2" :exclusions [log4j/log4j]]
64 | [precursor/om-i "0.1.7"]
65 | [prismatic/om-tools "0.3.11" :exclusions [om]]
66 | [prismatic/plumbing "0.4.4"]
67 | [prismatic/schema "0.4.4" :exclusions [prismatic/plumbing]]
68 | [racehub/om-bootstrap "0.5.1"]
69 | [ring "1.4.0" :exclusions [org.clojure/clojure commons-fileupload org.clojure/clojurescript]]
70 | [ring-basic-authentication "1.0.5"]
71 | [ring/ring-defaults "0.1.5"]
72 | [sablono "0.3.4"]
73 | [talaria "0.1.3"]]
74 |
75 | :cljsbuild {:test-commands {"test" ["phantomjs" "env/test/js/unit-test.js" "env/test/unit-test.html"]}
76 | :builds [{:id "dev"
77 | :source-paths ["env/dev/cljs/"
78 | "src/cljs" "src/shared/"
79 | "src/shared/"
80 | "vendor/datascript/src" "vendor/datascript/bench/src"
81 | "vendor/dato/src/cljs" "vendor/dato/src/shared"
82 | "vendor/garden/src"]
83 | :figwheel true
84 | :compiler {:asset-path "/js/bin-debug"
85 | :main datodomvc.client.dev
86 | :output-to "resources/public/js/bin-debug/main.js"
87 | :output-dir "resources/public/js/bin-debug/"
88 | :optimizations :none
89 | :pretty-print true
90 | :preamble ["react/react.js"]
91 | :externs ["react/externs/react.js"]
92 | :source-map true
93 | :verbose true
94 | :warnings {:single-segment-namespace false}}}
95 | {:id "pseudo"
96 | :source-paths ["src/cljs" "src/shared/"
97 | "vendor/datascript/src" "vendor/datascript/bench/src"
98 | "vendor/dato/src/cljs" "vendor/dato/src/shared"
99 | "vendor/garden/src"]
100 | :compiler {:asset-path "/js/bin-pseudo"
101 | :main datodomvc.client.production
102 | :output-to "resources/public/js/bin-pseudo/main.js"
103 | :output-dir "resources/public/js/bin-pseudo/"
104 | :optimizations :advanced
105 | :pseudo-names true
106 | :pretty-print true
107 | :preamble ["react/react.js"]
108 | :externs ["react/externs/react.js"]
109 | :source-map "resources/public/js/bin-pseudo/main.src"
110 | :verbose true
111 | :warnings {:single-segment-namespace false}}}
112 | {:id "test"
113 | :source-paths ["env/production/cljs"
114 | "src/cljs" "test/cljs"
115 | "vendor/datascript/src" "vendor/datascript/bench/src"
116 | "vendor/dato/src/cljs" "vendor/dato/src/shared"
117 | "vendor/garden/src"]
118 | :compiler {:pretty-print true
119 | :output-to "resources/public/cljs/test/frontend-dev.js"
120 | :output-dir "resources/public/cljs/test"
121 | :optimizations :advanced
122 | :externs ["datascript/externs.js"]
123 | :source-map "resources/public/cljs/test/sourcemap-dev.js"
124 | :warnings {:single-segment-namespace false}
125 | :verbose true}}
126 | {:id "production"
127 | :source-paths ["env/production/cljs"
128 | "src/cljs" "src/shared/"
129 | "vendor/datascript/src" "vendor/datascript/bench/src"
130 | "vendor/dato/src/cljs" "vendor/dato/src/shared"
131 | "vendor/garden/src"]
132 | :compiler {:asset-path "/js/bin"
133 | :main datodomvc.client.production
134 | :output-to "resources/public/js/bin/main.js"
135 | :output-dir "resources/public/js/bin/"
136 | :optimizations :advanced
137 | :pretty-print false
138 | :preamble ["react/react.js"]
139 | :externs ["react/externs/react.js"]
140 | :warnings {:single-segment-namespace false}
141 | :verbose true}}]}
142 |
143 | :figwheel {:http-server-root "public"
144 | :server-port 3449
145 | :server-ip "0.0.0.0"
146 | :css-dirs ["resources/public/css"]
147 | :open-file-command "emacsclient"}
148 |
149 | :main ^:skip-aot datodomvc.init
150 |
151 | :source-paths ["src/" "src/shared/"
152 | "vendor/datascript/src" "vendor/datascript/bench/src"
153 | "vendor/dato/src" "vendor/dato/src/shared"
154 | "vendor/dato/src/cljs"
155 | "vendor/garden/src"]
156 |
157 | :target-path "target/%s"
158 |
159 | :resource-paths ["resources" "resources/public"]
160 |
161 | :jvm-opts ["-server"
162 | "-Xss1m"
163 | "-Xmx4g"])
164 |
--------------------------------------------------------------------------------
/resources/public/css/base.css:
--------------------------------------------------------------------------------
1 | hr {
2 | margin: 20px 0;
3 | border: 0;
4 | border-top: 1px dashed #c5c5c5;
5 | border-bottom: 1px dashed #f7f7f7;
6 | }
7 |
8 | .learn a {
9 | font-weight: normal;
10 | text-decoration: none;
11 | color: #b83f45;
12 | }
13 |
14 | .learn a:hover {
15 | text-decoration: underline;
16 | color: #787e7e;
17 | }
18 |
19 | .learn h3,
20 | .learn h4,
21 | .learn h5 {
22 | margin: 10px 0;
23 | font-weight: 500;
24 | line-height: 1.2;
25 | color: #000;
26 | }
27 |
28 | .learn h3 {
29 | font-size: 24px;
30 | }
31 |
32 | .learn h4 {
33 | font-size: 18px;
34 | }
35 |
36 | .learn h5 {
37 | margin-bottom: 0;
38 | font-size: 14px;
39 | }
40 |
41 | .learn ul {
42 | padding: 0;
43 | margin: 0 0 30px 25px;
44 | }
45 |
46 | .learn li {
47 | line-height: 20px;
48 | }
49 |
50 | .learn p {
51 | font-size: 15px;
52 | font-weight: 300;
53 | line-height: 1.3;
54 | margin-top: 0;
55 | margin-bottom: 0;
56 | }
57 |
58 | .issue-count {
59 | display: none;
60 | }
61 |
62 | .quote {
63 | border: none;
64 | margin: 20px 0 60px 0;
65 | }
66 |
67 | .quote p {
68 | font-style: italic;
69 | }
70 |
71 | .quote p:before {
72 | content: '“';
73 | font-size: 50px;
74 | opacity: .15;
75 | position: absolute;
76 | top: -20px;
77 | left: 3px;
78 | }
79 |
80 | .quote p:after {
81 | content: '”';
82 | font-size: 50px;
83 | opacity: .15;
84 | position: absolute;
85 | bottom: -42px;
86 | right: 3px;
87 | }
88 |
89 | .quote footer {
90 | position: absolute;
91 | bottom: -40px;
92 | right: 0;
93 | }
94 |
95 | .quote footer img {
96 | border-radius: 3px;
97 | }
98 |
99 | .quote footer a {
100 | margin-left: 5px;
101 | vertical-align: middle;
102 | }
103 |
104 | .speech-bubble {
105 | position: relative;
106 | padding: 10px;
107 | background: rgba(0, 0, 0, .04);
108 | border-radius: 5px;
109 | }
110 |
111 | .speech-bubble:after {
112 | content: '';
113 | position: absolute;
114 | top: 100%;
115 | right: 30px;
116 | border: 13px solid transparent;
117 | border-top-color: rgba(0, 0, 0, .04);
118 | }
119 |
120 | .learn-bar > .learn {
121 | position: absolute;
122 | width: 272px;
123 | top: 8px;
124 | left: -300px;
125 | padding: 10px;
126 | border-radius: 5px;
127 | background-color: rgba(255, 255, 255, .6);
128 | transition-property: left;
129 | transition-duration: 500ms;
130 | }
131 |
132 | @media (min-width: 899px) {
133 | .learn-bar {
134 | width: auto;
135 | padding-left: 300px;
136 | }
137 |
138 | .learn-bar > .learn {
139 | left: 8px;
140 | }
141 | }
142 |
--------------------------------------------------------------------------------
/resources/public/css/index.css:
--------------------------------------------------------------------------------
1 | html,
2 | body {
3 | margin: 0;
4 | padding: 0;
5 | }
6 |
7 | button {
8 | margin: 0;
9 | padding: 0;
10 | border: 0;
11 | background: none;
12 | font-size: 100%;
13 | vertical-align: baseline;
14 | font-family: inherit;
15 | font-weight: inherit;
16 | color: inherit;
17 | -webkit-appearance: none;
18 | appearance: none;
19 | -webkit-font-smoothing: antialiased;
20 | -moz-font-smoothing: antialiased;
21 | font-smoothing: antialiased;
22 | }
23 |
24 | body {
25 | font: 14px 'Helvetica Neue', Helvetica, Arial, sans-serif;
26 | line-height: 1.4em;
27 | background: #f5f5f5;
28 | color: #4d4d4d;
29 | min-width: 230px;
30 | max-width: 550px;
31 | margin: 0 auto;
32 | -webkit-font-smoothing: antialiased;
33 | -moz-font-smoothing: antialiased;
34 | font-smoothing: antialiased;
35 | font-weight: 300;
36 | }
37 |
38 | button,
39 | input[type="checkbox"] {
40 | outline: none;
41 | }
42 |
43 | .hidden {
44 | display: none;
45 | }
46 |
47 | .todoapp {
48 | background: #fff;
49 | margin: 130px 0 40px 0;
50 | position: relative;
51 | box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.2),
52 | 0 25px 50px 0 rgba(0, 0, 0, 0.1);
53 | }
54 |
55 | .todoapp input::-webkit-input-placeholder {
56 | font-style: italic;
57 | font-weight: 300;
58 | color: #e6e6e6;
59 | }
60 |
61 | .todoapp input::-moz-placeholder {
62 | font-style: italic;
63 | font-weight: 300;
64 | color: #e6e6e6;
65 | }
66 |
67 | .todoapp input::input-placeholder {
68 | font-style: italic;
69 | font-weight: 300;
70 | color: #e6e6e6;
71 | }
72 |
73 | .todoapp h1 {
74 | position: absolute;
75 | top: -155px;
76 | width: 100%;
77 | font-size: 100px;
78 | font-weight: 100;
79 | text-align: center;
80 | color: rgba(175, 47, 47, 0.15);
81 | -webkit-text-rendering: optimizeLegibility;
82 | -moz-text-rendering: optimizeLegibility;
83 | text-rendering: optimizeLegibility;
84 | }
85 |
86 | .new-todo,
87 | .edit {
88 | position: relative;
89 | margin: 0;
90 | width: 100%;
91 | font-size: 24px;
92 | font-family: inherit;
93 | font-weight: inherit;
94 | line-height: 1.4em;
95 | border: 0;
96 | outline: none;
97 | color: inherit;
98 | padding: 6px;
99 | border: 1px solid #999;
100 | box-shadow: inset 0 -1px 5px 0 rgba(0, 0, 0, 0.2);
101 | box-sizing: border-box;
102 | -webkit-font-smoothing: antialiased;
103 | -moz-font-smoothing: antialiased;
104 | font-smoothing: antialiased;
105 | }
106 |
107 | .new-todo {
108 | padding: 16px 16px 16px 60px;
109 | border: none;
110 | background: rgba(0, 0, 0, 0.003);
111 | box-shadow: inset 0 -2px 1px rgba(0,0,0,0.03);
112 | }
113 |
114 | .main {
115 | position: relative;
116 | z-index: 2;
117 | border-top: 1px solid #e6e6e6;
118 | }
119 |
120 | label[for='toggle-all'] {
121 | display: none;
122 | }
123 |
124 | .toggle-all {
125 | position: absolute;
126 | top: -55px;
127 | left: -12px;
128 | width: 60px;
129 | height: 34px;
130 | text-align: center;
131 | border: none; /* Mobile Safari */
132 | }
133 |
134 | .toggle-all:before {
135 | content: '❯';
136 | font-size: 22px;
137 | color: #e6e6e6;
138 | padding: 10px 27px 10px 27px;
139 | }
140 |
141 | .toggle-all:checked:before {
142 | color: #737373;
143 | }
144 |
145 | .todo-list {
146 | margin: 0;
147 | padding: 0;
148 | list-style: none;
149 | }
150 |
151 | .todo-list li {
152 | position: relative;
153 | font-size: 24px;
154 | border-bottom: 1px solid #ededed;
155 | }
156 |
157 | .todo-list li:last-child {
158 | border-bottom: none;
159 | }
160 |
161 | .todo-list li.editing {
162 | border-bottom: none;
163 | padding: 0;
164 | }
165 |
166 | .todo-list li.editing .edit {
167 | display: block;
168 | width: 506px;
169 | padding: 13px 17px 12px 17px;
170 | margin: 0 0 0 43px;
171 | }
172 |
173 | .todo-list li.editing .view {
174 | display: none;
175 | }
176 |
177 | .todo-list li .toggle {
178 | text-align: center;
179 | width: 40px;
180 | /* auto, since non-WebKit browsers doesn't support input styling */
181 | height: auto;
182 | position: absolute;
183 | top: 0;
184 | bottom: 0;
185 | margin: auto 0;
186 | border: none; /* Mobile Safari */
187 | -webkit-appearance: none;
188 | appearance: none;
189 | }
190 |
191 | .todo-list li .toggle:after {
192 | content: url('data:image/svg+xml;utf8,');
193 | }
194 |
195 | .todo-list li .toggle:checked:after {
196 | content: url('data:image/svg+xml;utf8,');
197 | }
198 |
199 | .todo-list li label {
200 | white-space: pre;
201 | word-break: break-word;
202 | padding: 15px 60px 15px 15px;
203 | margin-left: 45px;
204 | display: block;
205 | line-height: 1.2;
206 | transition: color 0.4s;
207 | }
208 |
209 | .todo-list li.completed label {
210 | color: #d9d9d9;
211 | text-decoration: line-through;
212 | }
213 |
214 | .todo-list li .destroy {
215 | display: none;
216 | position: absolute;
217 | top: 0;
218 | right: 10px;
219 | bottom: 0;
220 | width: 40px;
221 | height: 40px;
222 | margin: auto 0;
223 | font-size: 30px;
224 | color: #cc9a9a;
225 | margin-bottom: 11px;
226 | transition: color 0.2s ease-out;
227 | }
228 |
229 | .todo-list li .destroy:hover {
230 | color: #af5b5e;
231 | }
232 |
233 | .todo-list li .destroy:after {
234 | content: '×';
235 | }
236 |
237 | .todo-list li:hover .destroy {
238 | display: block;
239 | }
240 |
241 | .todo-list li .edit {
242 | display: none;
243 | }
244 |
245 | .todo-list li.editing:last-child {
246 | margin-bottom: -1px;
247 | }
248 |
249 | .footer {
250 | color: #777;
251 | padding: 10px 15px;
252 | height: 20px;
253 | text-align: center;
254 | border-top: 1px solid #e6e6e6;
255 | }
256 |
257 | .footer:before {
258 | content: '';
259 | position: absolute;
260 | right: 0;
261 | bottom: 0;
262 | left: 0;
263 | height: 50px;
264 | overflow: hidden;
265 | box-shadow: 0 1px 1px rgba(0, 0, 0, 0.2),
266 | 0 8px 0 -3px #f6f6f6,
267 | 0 9px 1px -3px rgba(0, 0, 0, 0.2),
268 | 0 16px 0 -6px #f6f6f6,
269 | 0 17px 2px -6px rgba(0, 0, 0, 0.2);
270 | }
271 |
272 | .todo-count {
273 | float: left;
274 | text-align: left;
275 | }
276 |
277 | .todo-count strong {
278 | font-weight: 300;
279 | }
280 |
281 | .filters {
282 | margin: 0;
283 | padding: 0;
284 | list-style: none;
285 | position: absolute;
286 | right: 0;
287 | left: 0;
288 | }
289 |
290 | .filters li {
291 | display: inline;
292 | }
293 |
294 | .filters li a {
295 | color: inherit;
296 | margin: 3px;
297 | padding: 3px 7px;
298 | text-decoration: none;
299 | border: 1px solid transparent;
300 | border-radius: 3px;
301 | }
302 |
303 | .filters li a.selected,
304 | .filters li a:hover {
305 | border-color: rgba(175, 47, 47, 0.1);
306 | }
307 |
308 | .filters li a.selected {
309 | border-color: rgba(175, 47, 47, 0.2);
310 | }
311 |
312 | .clear-completed,
313 | html .clear-completed:active {
314 | float: right;
315 | position: relative;
316 | line-height: 20px;
317 | text-decoration: none;
318 | cursor: pointer;
319 | position: relative;
320 | }
321 |
322 | .clear-completed:hover {
323 | text-decoration: underline;
324 | }
325 |
326 | .info {
327 | margin: 65px auto 0;
328 | color: #bfbfbf;
329 | font-size: 10px;
330 | text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
331 | text-align: center;
332 | }
333 |
334 | .info p {
335 | line-height: 1;
336 | }
337 |
338 | .info a {
339 | color: inherit;
340 | text-decoration: none;
341 | font-weight: 400;
342 | }
343 |
344 | .info a:hover {
345 | text-decoration: underline;
346 | }
347 |
348 | /*
349 | Hack to remove background from Mobile Safari.
350 | Can't use it globally since it destroys checkboxes in Firefox
351 | */
352 | @media screen and (-webkit-min-device-pixel-ratio:0) {
353 | .toggle-all,
354 | .todo-list li .toggle {
355 | background: none;
356 | }
357 |
358 | .todo-list li .toggle {
359 | height: 40px;
360 | }
361 |
362 | .toggle-all {
363 | -webkit-transform: rotate(90deg);
364 | transform: rotate(90deg);
365 | -webkit-appearance: none;
366 | appearance: none;
367 | }
368 | }
369 |
370 | @media (max-width: 430px) {
371 | .footer {
372 | height: 50px;
373 | }
374 |
375 | .filters {
376 | bottom: 10px;
377 | }
378 | }
379 |
--------------------------------------------------------------------------------
/src/cljs/datodomvc/client/components/root.cljs:
--------------------------------------------------------------------------------
1 | (ns datodomvc.client.components.root
2 | (:require [clojure.string :as string]
3 | [datascript :as d]
4 | [dato.db.utils :as dsu]
5 | [dato.lib.controller :as con]
6 | [dato.lib.core :as dato]
7 | [dato.lib.db :as db]
8 | [datodomvc.client.routes :as routes]
9 | [datodomvc.client.utils :as utils]
10 | [om.core :as om :include-macros true]
11 | [om-tools.core :refer-macros [defcomponent]]
12 | [sablono.core :as html :refer-macros [html]]))
13 |
14 | (defn kill! [event]
15 | (doto event
16 | (.preventDefault)
17 | (.stopPropagation)))
18 |
19 | (defn delay-focus!
20 | "Waits 20ms (enough time to queue up a rerender usually, but
21 | racey) and then focus an input"
22 | ([root selector]
23 | (delay-focus! root selector false))
24 | ([root selector select?]
25 | (js/setTimeout #(when-let [input (utils/sel1 root selector)]
26 | (.focus input)
27 | (when select?
28 | (.select input))) 20)))
29 |
30 | ;; Useful to show what's being rerendered (everything right now for
31 | ;; the PoC demo)
32 | (defn rand-color []
33 | (str "#" (string/join (repeatedly 6 #(rand-nth [1 2 3 4 5 6 7 8 9 0 "A" "B" "C" "D" "E" "F"])))))
34 |
35 | (defmethod con/transition :server/find-tasks-succeeded
36 | [db {:keys [data] :as args}]
37 | ;; The pull request is insertable as-is, so we don't need to do any
38 | ;; pre-processing, just return the results.
39 | ;;
40 | ;; XXX: We're not picking up on the ref attr properly, so it's not
41 | ;; actually insertable as-is. This can probably be moved love down
42 | ;; the Dato stack. Either way, Preprocessing step for ref-attrs (to
43 | ;; handle the diff between DS/Datomic re: enums) needs to be
44 | ;; eliminated.
45 | (let [results (:results data)]
46 | (mapv (fn [entity-like]
47 | (->> entity-like
48 | (map (fn [[k v]]
49 | (if (and (dsu/ref-attr? db k)
50 | (keyword? v))
51 | [k (db/enum-id db v)]
52 | [k v])))
53 | (into {}))) results)))
54 |
55 | (defmethod con/transition :ui/item-inspected
56 | [db {:keys [data] :as args}]
57 | (let [session (dato/local-session db)
58 | inspected-type (keyword (name (:type data)))]
59 | [{:db/id (:db/id session)
60 | :session/task-filter inspected-type}]))
61 |
62 | (defmethod con/effect! :server/find-tasks-succeeded
63 | ;; Router is from the context we passed in when instantiating our
64 | ;; app in core.cljs
65 | [{:keys [router] :as context} old-db new-db exhibit]
66 | (routes/start! router))
67 |
68 | (defcomponent root-com [data owner opts]
69 | (display-name [_]
70 | "DatodoMVC")
71 | (did-mount [_]
72 | (d/listen! (dato/conn (om/get-shared owner :dato)) :dato-root #(om/refresh! owner)))
73 | (will-unmount [_]
74 | (d/unlisten! (dato/conn (om/get-shared owner :dato)) :dato-root))
75 | (render [_]
76 | (html
77 | (let [{:keys [dato]} (om/get-shared owner)
78 | db (dato/db dato)
79 | transact! (partial dato/transact! dato)
80 | me (dato/me db)
81 | session (dato/local-session db)
82 | task-filter (:session/task-filter session)
83 | pred (case task-filter
84 | :completed :task/completed?
85 | :active (complement :task/completed?)
86 | (constantly true))
87 | all-tasks (dsu/qes-by db :task/title)
88 | grouped (group-by :task/completed? all-tasks)
89 | active-tasks (get grouped false)
90 | completed-tasks (get grouped true)
91 | shown-tasks (->> all-tasks
92 | (filter pred)
93 | (sort-by :task/order))]
94 | [:div
95 | [:section.todoapp
96 | [:header.header
97 | [:h1 "Todos"]
98 | [:input.new-todo {:placeholder "What needs to be done?"
99 | :autofocus true
100 | :value (om/get-state owner :new-task-title)
101 | :on-change #(om/set-state! owner :new-task-title (.. % -target -value))
102 | :on-key-down (fn [event]
103 | (when (= 13 (.-which event))
104 | (let [task {:db/id (d/tempid :db.part/user)
105 | :dato/guid (d/squuid)
106 | :dato/type (db/enum-id db :datodomvc.types/task)
107 | :task/title (om/get-state owner :new-task-title)
108 | :task/completed? false
109 | :task/order (count all-tasks)}]
110 | (transact! :task-created [task] {:tx/persist? true})
111 | (om/set-state! owner :new-task-title nil))))}]]
112 | [:section.main
113 | (when (first all-tasks)
114 | [:input.toggle-all {:type "checkbox"
115 | :on-change (fn [event]
116 | (let [checked? (.. event -target -checked)]
117 | (transact! (keyword (str "tasks-all-marked-" (if checked? "complete" "incomplete")))
118 | (vec (for [task all-tasks]
119 | [:db/add (:db/id task) :task/completed? checked?])) {:tx/persist? true})))
120 | :checked (not (boolean (first active-tasks)))}])
121 | [:label {:for "toggle-all"} "Mark all as complete"]
122 | (into
123 | [:ul.todo-list]
124 | (for [task shown-tasks]
125 | ^{:key (str "task-item-" (:db/id task))}
126 | [:li {:key (str "task-item-" (:db/id task))
127 | :class (cond
128 | (:task/completed? task) "completed"
129 | (= (om/get-state owner [:editing :id]) (:db/id task)) "editing")
130 | :on-double-click (fn [event]
131 | (om/set-state! owner :editing {:id (:db/id task)
132 | :original (:task/title task)})
133 | (delay-focus! (om/get-node owner) (str ".task-" (:db/id task)) true))}
134 | [:div.view
135 | [:input.toggle {:type "checkbox"
136 | :checked (:task/completed? task)
137 | :on-change (fn [event]
138 | (transact! :task-toggled [{:db/id (:db/id task)
139 | :task/completed? (not (:task/completed? task))}]
140 | {:tx/persist? true}))}]
141 | [:label (:task/title task)]
142 | [:button.destroy {:on-click #(transact! :task-destroyed [[:db.fn/retractEntity (:db/id task)]] {:tx/persist? true})}]]
143 | [:input.edit {:class (str "task-" (:db/id task))
144 | :value (:task/title task)
145 | :on-key-down #(condp = (.-which %)
146 | 13 (om/set-state! owner :editing {})
147 | 27 (do
148 | (transact! :task-title-restored [{:db/id (:db/id task)
149 | :task/title (om/get-state owner [:editing :original])}] {:tx/persist? true})
150 | (om/set-state! owner :editing {}))
151 | nil)
152 | :on-change #(transact! :task-title-edited [{:db/id (:db/id task)
153 | :task/title (.. % -target -value)}] {:tx/persist? true})}]]))]
154 | [:footer.footer
155 | [:span.todo-count [:strong (count active-tasks)] " items left"]
156 | [:ul.filters
157 | [:li
158 | [:a {:href (routes/url-for :tasks/all)
159 | :class (when (or (= :all task-filter) (not task-filter)) "selected")
160 | :on-click (fn [event]
161 | (kill! event)
162 | (transact! :filter-updated [{:db/id (:db/id session)
163 | :session/task-filter :all}]))} "All"]]
164 | [:li
165 | [:a {:href (routes/url-for :tasks/active)
166 | :class (when (= :active task-filter) "selected")
167 | :on-click (fn [event]
168 | (kill! event)
169 | (transact! :filter-updated [{:db/id (:db/id session)
170 | :session/task-filter :active}]))} "Active"]]
171 | [:li
172 | [:a {:href (routes/url-for :tasks/completed)
173 | :class (when (= :completed task-filter) "selected")
174 | :on-click (fn [event]
175 | (kill! event)
176 | (transact! :filter-updated [{:db/id (:db/id session)
177 | :session/task-filter :completed}]))} "Completed"]]]
178 | (when (first completed-tasks)
179 | [:button.clear-completed
180 | {:on-click #(transact! :completed-tasks-cleared (->> all-tasks
181 | (filter :task/completed?)
182 | (mapv (fn [task] [:db.fn/retractEntity (:db/id task)]))) {:tx/persist? true})}
183 | "Clear completed"])]]
184 | [:footer.info
185 | [:p "Double-click to edit a todo"]
186 | [:p "Created by "
187 | [:a {:href "https://twitter.com/sgrove"} "Sean Grove"]]
188 | [:p "Part of "
189 | [:a {:href "http://todomvc.com"} "TodoMVC"]]]]))))
190 |
--------------------------------------------------------------------------------
/src/cljs/datodomvc/client/config.cljs:
--------------------------------------------------------------------------------
1 | (ns datodomvc.client.config)
2 |
3 | (defn config []
4 | (aget js/window "DatodoMVC" "config"))
5 |
6 | (defn dato-port []
7 | (aget (config) "dato-port"))
8 |
--------------------------------------------------------------------------------
/src/cljs/datodomvc/client/core.cljs:
--------------------------------------------------------------------------------
1 | (ns ^:figwheel-always datodomvc.client.core
2 | (:require [cljs.core.async :as async :refer [put! chan > args
32 | (mapcat (fn [[k v]]
33 | [k (cond
34 | (com.cognitect.transit.types/isUUID v) (cljs.core.UUID. (str v))
35 | (instance? datascript.impl.entity/Entity v) (dsu/touch+ v)
36 | :else v)]))
37 | vec)]
38 | (apply bidi/path-for routes action args))))
39 |
40 | (defn navigate-to! [router action params]
41 | (let [route (url-for action params)]
42 | (pushy/set-token! router route)))
43 |
44 | (defn make-router [dato]
45 | (pushy/pushy (make-route-dispatcher dato) parse-url))
46 |
47 | (defn start! [router]
48 | (pushy/start! router))
49 |
--------------------------------------------------------------------------------
/src/cljs/datodomvc/client/utils.cljs:
--------------------------------------------------------------------------------
1 | (ns datodomvc.client.utils
2 | (:require [clojure.string :as string]
3 | [goog.dom.DomHelper :as gdomh]
4 | [goog.Uri])
5 | (:import [goog.Uri]))
6 |
7 | (defn map-vals
8 | "Create a new map from m by calling function f on each value to get a new value."
9 | [m f & args]
10 | (when m
11 | (into {}
12 | (for [[k v] m]
13 | [k (apply f v args)]))))
14 |
15 | (defn map-keys
16 | "Create a new map from m by calling function f on each key to get a new key."
17 | [m f & args]
18 | (when m
19 | (into {}
20 | (for [[k v] m]
21 | [(apply f k args) v]))))
22 |
23 | (def parsed-uri
24 | (goog.Uri. (-> (.-location js/window) (.-href))))
25 |
26 | (defn uri-param [parsed-uri param-name & [not-found]]
27 | (let [v (.getParameterValue parsed-uri param-name)]
28 | (cond
29 | (= v "") [(keyword param-name) not-found]
30 | (undefined? v) [(keyword param-name) not-found]
31 | (= v "true") [(keyword (str param-name "?")) true]
32 | (= v "false") [(keyword (str param-name "?")) false]
33 | (= (.toString (js/parseInt v)) v) [(keyword param-name) (js/parseInt v)]
34 | (re-matches #"^\d+\.\d*" v) [(keyword param-name) (js/parseFloat v)]
35 | :else [(keyword param-name) v])))
36 |
37 | (def initial-query-map
38 | (let [parsed-uri (goog.Uri. (.. js/window -location -href))
39 | ks (.. parsed-uri getQueryData getKeys)
40 | defaults {}
41 | initial (reduce merge {} (map (partial uri-param parsed-uri) (clj->js ks)))
42 | ;; Use this if you need to do any fn-based changes, e.g. split on a uri param
43 | special {}]
44 | (merge defaults initial special)))
45 |
46 | (defn log [& msg]
47 | (.apply (.-log js/console) js/console (clj->js msg)))
48 |
49 | (defn sel1
50 | ([query]
51 | (sel1 js/document query))
52 | ([node query]
53 | (.querySelector node (name query))))
54 |
55 | (defn destroy-sel!
56 | ([selector]
57 | (destroy-sel! js/document selector))
58 | ([node selector]
59 | (gdomh/removeNode (sel1 node selector))))
60 |
61 | (defn map->query-params [m]
62 | (reduce (fn [run [k v]]
63 | (let [lead (if run "&" "")]
64 | (str run lead (js/encodeURIComponent (name k)) "=" (js/encodeURIComponent v)))) nil
65 | m))
66 |
--------------------------------------------------------------------------------
/src/datodomvc/config.clj:
--------------------------------------------------------------------------------
1 | (ns datodomvc.config
2 | (:require [environ.core :as env]))
3 |
4 | (defn datomic-uri []
5 | (or (env/env :datomic-uri)
6 | "datomic:sql://datodomvc?jdbc:postgresql://my-remote-server:5432/datodomvc?user=datomic&password=datomic"))
7 |
8 | (defn dev? []
9 | (env/env :is-dev))
10 |
11 | (defn nrepl-port []
12 | (when-let [port (env/env :nrepl-port)]
13 | (Integer/parseInt port)))
14 |
15 | (defn dato-port []
16 | (if-let [port (env/env :dato-port)]
17 | (Integer/parseInt port)
18 | 8080))
19 |
20 | (defn server-port []
21 | (if-let [port (env/env :server-port)]
22 | (Integer/parseInt port)
23 | 10555))
24 |
--------------------------------------------------------------------------------
/src/datodomvc/core.clj:
--------------------------------------------------------------------------------
1 | (ns datodomvc.core
2 | (:require [datodomvc.server :as server])
3 | (:gen-class))
4 |
5 | (defn -main
6 | [& port]
7 | (server/run port))
8 |
--------------------------------------------------------------------------------
/src/datodomvc/datomic/core.clj:
--------------------------------------------------------------------------------
1 | (ns datodomvc.datomic.core
2 | (:require [clojure.core.async :as async]
3 | [clojure.tools.logging :refer (infof)]
4 | [clojure.walk :as walk]
5 | [datomic.api :refer [q] :as d]
6 | [datodomvc.config :as config]
7 | [dato.db.utils :as dsu])
8 | (:import java.util.UUID))
9 |
10 |
11 | (def remote-uri (config/datomic-uri))
12 |
13 | (def local-uri (config/datomic-uri))
14 |
15 | (def default-uri
16 | (if (config/dev?)
17 | local-uri
18 | remote-uri))
19 |
20 | (defn make-conn [& [options]]
21 | (d/connect (or (:uri options) default-uri)))
22 |
23 | (defn conn []
24 | (make-conn))
25 |
26 | (defn ddb []
27 | (d/db (conn)))
28 |
29 | (defn init []
30 | (infof "Creating default database if it doesn't exist: %s"
31 | (d/create-database default-uri))
32 | (infof "Ensuring connection to default database")
33 | (infof "Connected to: %s" (conn)))
34 |
--------------------------------------------------------------------------------
/src/datodomvc/datomic/migrations.clj:
--------------------------------------------------------------------------------
1 | (ns datodomvc.datomic.migrations
2 | (:require [datodomvc.datomic.core :as db-conn]
3 | [clojure.tools.logging :as log]
4 | [datomic.api :refer [db q] :as d])
5 | (:import java.util.UUID))
6 |
7 | (defn migration-entity
8 | "Finds the entity that keeps track of the migration version, there should
9 | be only one of these."
10 | [db]
11 | (d/entity db (d/q '[:find ?t .
12 | :where [?t :migration/version]]
13 | db)))
14 |
15 | (defn migration-version
16 | "Gets the migration version, or returns -1 if no migrations have run."
17 | [db]
18 | (:migration/version (migration-entity db) -1))
19 |
20 | (defn update-migration-version
21 | "Updates the migration version, throwing an exception if the version does not increase
22 | the previous version by 1."
23 | [conn version]
24 | (let [e (migration-entity (db conn))]
25 | @(d/transact conn [[:db.fn/cas (:db/id e) :migration/version (dec version) version]])))
26 |
27 | (defn add-migrations-entity
28 | "First migration, adds the entity that keep track of the migration version."
29 | [conn]
30 | (assert (= -1 (migration-version (db conn))))
31 | ;; This will set it to -1, then update-migration-version will set it to 0
32 | @(d/transact conn [{:db/id (d/tempid :db.part/user) :migration/version -1}]))
33 |
34 | (defn create-dummy-users
35 | "Creates a few dummy users for testing"
36 | [conn]
37 | @(d/transact conn [{:db/id (d/tempid :db.part/user)
38 | :user/id (d/squuid)
39 | :user/email "dwwoelfel@gmail.com"
40 | :user/given-name "Daniel"
41 | :user/family-name "Woelfel"}
42 | {:db/id (d/tempid :db.part/user)
43 | :user/id (d/squuid)
44 | :user/email "sean@example.com"
45 | :user/given-name "Sean"
46 | :user/family-name "Grove"}]))
47 |
48 | (def migrations
49 | "Array-map of migrations, the migration version is the key in the map.
50 | Use an array-map to make it easier to resolve merge conflicts."
51 | [[0 #'add-migrations-entity]
52 | [1 #'create-dummy-users]
53 | ])
54 |
55 | (defn necessary-migrations
56 | "Returns tuples of migrations that need to be run, e.g. [[0 #'migration-one]]"
57 | [conn]
58 | (drop (inc (migration-version (db conn))) migrations))
59 |
60 | (defn run-necessary-migrations [conn]
61 | (doseq [[version migration] (necessary-migrations conn)]
62 | (log/infof "migrating datomic db to version %s with %s" version migration)
63 | (migration conn)
64 | (update-migration-version conn version)))
65 |
66 | (defn init []
67 | (run-necessary-migrations (db-conn/conn)))
68 |
--------------------------------------------------------------------------------
/src/datodomvc/datomic/schema.clj:
--------------------------------------------------------------------------------
1 | (ns datodomvc.datomic.schema
2 | (:require [datodomvc.datomic.core :as db-conn]
3 | [dato.db.utils :as dsu]
4 | [datomic.api :refer [db q] :as d]))
5 |
6 | (defn attribute [ident type & {:as opts}]
7 | (merge {:db/id (d/tempid :db.part/db)
8 | :db/ident ident
9 | :db/valueType type
10 | :db.install/_attribute :db.part/db}
11 | {:db/cardinality :db.cardinality/one}
12 | opts))
13 |
14 | (defn function [ident fn & {:as opts}]
15 | (merge {:db/id (d/tempid :db.part/user)
16 | :db/ident ident
17 | :db/fn fn}
18 | opts))
19 |
20 | (defn enum [ident]
21 | {:db/id (d/tempid :db.part/user)
22 | :db/ident ident
23 | :dato/guid (d/squuid)})
24 |
25 | (def schema-1
26 | ;; Universal attributes
27 | [(attribute :migration/version :db.type/long)
28 | (attribute :dato/type :db.type/ref)
29 | (attribute :dato/guid :db.type/uuid :db/unique :db.unique/identity)
30 | (attribute :tx/guid :db.type/uuid :db/unique :db.unique/identity)
31 | (attribute :tx/session-id :db.type/string)])
32 |
33 | (def schema-2
34 | (vec
35 | (concat
36 | ;; TodoMVC Types
37 | [(enum :datodomvc.types/task)
38 | (enum :datodomvc.types/user)]
39 |
40 | ;; Users
41 | [(attribute :user/id :db.type/uuid :db/unique :db.unique/identity)
42 | (attribute :user/email :db.type/string :db/unique :db.unique/identity)
43 | (attribute :user/given-name :db.type/string)
44 | (attribute :user/family-name :db.type/string)]
45 |
46 | ;; Tasks
47 | [(attribute :task/user :db.type/ref)
48 | (attribute :task/title :db.type/string)
49 | (attribute :task/completed? :db.type/boolean)
50 | (attribute :task/order :db.type/long)])))
51 |
52 | (defonce schema-ents
53 | (atom nil))
54 |
55 | (defn enums []
56 | (->> @schema-ents
57 | (filter #(= :db.type/ref (:db/valueType %)))
58 | (map :db/ident )
59 | (set)))
60 |
61 | (defn get-ident [a]
62 | (->> @schema-ents
63 | (filter #(= a (:db/id %)) )
64 | first
65 | :db/ident))
66 |
67 | (defn get-schema-ents [db]
68 | (dsu/touch-all '{:find [?t]
69 | :where [[?t :db/ident ?ident]]}
70 | db))
71 |
72 | (defn ensure-schema
73 | ([] (ensure-schema (db-conn/conn)))
74 | ([conn]
75 | (let [res @(d/transact conn schema-1)
76 | res @(d/transact conn schema-2)
77 | ents (get-schema-ents (:db-after res))]
78 | (reset! schema-ents ents)
79 | res)))
80 |
81 | (defn init []
82 | (ensure-schema))
83 |
84 | ;; (init)
85 |
--------------------------------------------------------------------------------
/src/datodomvc/init.clj:
--------------------------------------------------------------------------------
1 | (ns datodomvc.init
2 | (:require [datodomvc.datomic.core]
3 | [datodomvc.datomic.migrations]
4 | [datodomvc.datomic.schema]
5 | [datodomvc.nrepl]
6 | [datodomvc.server])
7 | (:import [java.util Date]))
8 |
9 | (defn init []
10 | (datodomvc.nrepl/init)
11 | (datodomvc.datomic.core/init)
12 | (datodomvc.datomic.schema/init)
13 | (datodomvc.datomic.migrations/init)
14 | (datodomvc.server/init))
15 |
16 | (defn -main []
17 | (println "Initializing dato at" (Date.))
18 | (init)
19 | (println "Finished initializing dato at" (Date.)))
20 |
--------------------------------------------------------------------------------
/src/datodomvc/nrepl.clj:
--------------------------------------------------------------------------------
1 | (ns datodomvc.nrepl
2 | (:require [clojure.tools.nrepl.server :refer (start-server)]
3 | [cider.nrepl]
4 | [datodomvc.config :as config]))
5 |
6 | (defn init []
7 | (if-let [port (config/nrepl-port)]
8 | (do
9 | (println "Starting nrepl on port" port)
10 | (start-server :port port :handler cider.nrepl/cider-nrepl-handler))
11 | (println "Not starting nrepl, export NREPL_PORT to start an embedded nrepl server")))
12 |
--------------------------------------------------------------------------------
/src/datodomvc/server.clj:
--------------------------------------------------------------------------------
1 | (ns datodomvc.server
2 | (:require [bidi.bidi :as bidi]
3 | [cheshire.core :as json]
4 | [clojure.java.io :as io]
5 | [compojure.core :refer [defroutes GET POST]]
6 | [compojure.route :as route]
7 | [datomic.api :as d]
8 | [dato.db.utils :as dsu]
9 | [dato.lib.debug :as dato-debug]
10 | [dato.lib.server :as dato]
11 | [datodomvc.datomic.core :as db-conn]
12 | [datodomvc.config :as config]
13 | [hiccup.core :as h]
14 | [immutant.codecs :as cdc]
15 | [ring.adapter.jetty :as jetty]
16 | [ring.middleware.basic-authentication :as basic-auth]
17 | [ring.middleware.defaults :as ring-defaults]
18 | [ring.middleware.gzip :as gzip]
19 | [ring.middleware.multipart-params :as multipart]
20 | [ring.middleware.reload :as reload]
21 | [ring.util.response :as resp])
22 | (:import [java.net URLEncoder]
23 | [java.util UUID]))
24 |
25 | (defn build-name->entry-file [build-name]
26 | (case build-name
27 | "pseudo" "/js/bin-pseudo/main.js"
28 | "production" "/js/bin/main.js"
29 | "dev" "/js/bin-debug/main.js"
30 | (if (config/dev?)
31 | "/js/bin-debug/main.js"
32 | "/js/bin/main.js")))
33 |
34 | (defn bootstrap-html [params]
35 | ;; TODO: Add some authorization here to make sure user is allowed to
36 | ;; access different version of the js.
37 | (let [header [:head
38 | [:link {:href "/css/base.css" :rel "stylesheet" :type "text/css"}]
39 | [:link {:href "/css/index.css" :rel "stylesheet" :type "text/css"}]
40 | [:title "Dato • TodoMVC"]
41 | [:script {:type "text/javascript"}
42 | (format "DatodoMVC = {}; DatodoMVC.config = JSON.parse('%s');" (json/encode {:dato-port (config/dato-port)}))]]]
43 | (h/html [:html
44 | header
45 | [:body
46 | [:div#datodomvc-app
47 | [:input.history {:style "display:none;"}]
48 | [:div.app-instance "Please wait while the app loads..."]
49 | [:div.debugger-container]]
50 | [:script {:src (build-name->entry-file (:build-name params))}]]])))
51 |
52 | (defroutes routes
53 | (GET "/_source" request
54 | (let [path (get-in request [:params :path])
55 | macros? (get-in request [:params :macros])]
56 | {:body (json/generate-string (dato-debug/source-path->source macros? path))}))
57 | (route/resources "/")
58 | (GET "/*" request
59 | (bootstrap-html (:params request))))
60 |
61 | (defn authenticated? [email pass]
62 | false)
63 |
64 | (def http-handler
65 | (as-> (var routes) routes
66 | (ring-defaults/wrap-defaults routes ring-defaults/api-defaults)
67 | (multipart/wrap-multipart-params routes)
68 | (gzip/wrap-gzip routes)
69 | (if (config/dev?)
70 | (reload/wrap-reload routes)
71 | (basic-auth/wrap-basic-authentication routes authenticated?))))
72 |
73 | (defn run-web-server []
74 | (let [port (config/server-port)]
75 | (print "Starting web server on port" port ".\n")
76 | (jetty/run-jetty http-handler {:port port :join? false})))
77 |
78 | (defn handler [{c :context}]
79 | (resp/redirect (str c "/index.html")))
80 |
81 | (def routing-table
82 | {})
83 |
84 | (def dato-routes
85 | (dato/new-routing-table routing-table))
86 |
87 | (def dato-server
88 | (dato/map->DatoServer {:routing-table #'dato-routes
89 | :datomic-uri db-conn/default-uri}))
90 |
91 | (defn run []
92 | (dato/start! handler {:server (var dato-server)
93 | :port (config/dato-port)})
94 | (run-web-server))
95 |
96 | (defn init []
97 | (run))
98 |
99 | (comment
100 | (do
101 | (require '[datodomvc.dev :as dev])
102 | (datodomvc.dev/browser-repl)))
103 |
--------------------------------------------------------------------------------
/src/shared/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/datodev/datodomvc/f6d65b61e2fe135a27e870f9a9613f204ded09a9/src/shared/.gitkeep
--------------------------------------------------------------------------------
/test/datodomvc/core_test.clj:
--------------------------------------------------------------------------------
1 | (ns datodomvc.core-test
2 | (:require [clojure.test :refer :all]
3 | [datodomvc.core :refer :all]))
4 |
5 | (deftest a-test
6 | (testing "FIXME, I fail."
7 | (is (= 0 1))))
8 |
--------------------------------------------------------------------------------