-
Notifications
You must be signed in to change notification settings - Fork 361
DataScript Integration Tutorial
In this short tutorial we'll see how easy it is to integrate custom data sources into Om Next applications.
This tutorial uses Leiningen, Figwheel, and Google Chrome. You should install Leiningen and Google Chrome before proceeding. Leiningen is a standard tool for managing Clojure and ClojureScript library dependencies. Figwheel is a ClojureScript build tool and REPL that enables an expressive live programming model well suited for interactive application development. Figwheel also plays well with text editors that make traditional REPL integration more challenging.
You can of course use any web browser, but this tutorial only includes relevant instructions for Chrome to avoid tangential material.
Create a new project and switch into it:
mkdir om-datascript
cd om-datascript
Inside your project directory create a project.clj
:
touch project.clj
Make it look like the following:
(defproject om-datascript "0.1.0-SNAPSHOT"
:description "My first Om program!"
:dependencies [[org.clojure/clojure "1.7.0"]
[org.clojure/clojurescript "1.7.122"]
[org.omcljs/om "0.9.0-SNAPSHOT"]
[datascript "0.13.1"]
[figwheel-sidecar "0.4.0" :scope "provided"]])
A Leiningen project.clj
file simply allows you to declare a variety
of properties about your project. In our the case the most important
is the list of :dependencies
.
Now create a file script/figwheel.clj
.
mkdir script
touch script/figwheel.clj
Change script/figwheel.clj
to look like the following:
(require '[figwheel-sidecar.repl :as r]
'[figwheel-sidecar.repl-api :as ra])
(ra/start-figwheel!
{:figwheel-options {}
:build-ids ["dev"]
:all-builds
[{:id "dev"
:figwheel true
:source-paths ["src"]
:compiler {:main 'om-datascript.core
:asset-path "js"
:output-to "resources/public/js/main.js"
:output-dir "resources/public/js"
:verbose true}}]})
(ra/cljs-repl)
This file describes how to build your ClojureScript project and starts a REPL. If you are new to ClojureScript you may find this file a bit overwhelming. If you would like to know more, after this tutorial you may want to work through the ClojureScript Quick Start to re-inforce fundamental ClojureScript concepts encountered in this tutorial.