Component calls itself a tiny framework for managing the lifecycle and
dependencies of software components which have runtime state. It’s a helpful
tool for making runtime dependencies explicit, and it’s a great addition to a
REPL based workflow.
Component is platform independent, the examples in this episode will focus on
Clojure, but you can use it in ClojureScript just the same.
Component makes heavy use of records and protocols, two Clojure features that
not everyone will be familiar with. If you need a refresher you can check out
episode 23 and 24, which cover these in depth.
With that out of the way, let’s have a look at Component. Component is just a
library, so to get started add it as a dependency to your
(defproject component-example "0.1.0-SNAPSHOT"
:dependencies [[org.clojure/clojure "1.8.0"]
If you want to follow along you can also clone the
lambdaisland/component_example project from Github and grab the
branch. This branch already contains all dependencies used in this episode, as
well as a few utility functions that will come in handy later on.
git clone https://github.com/lambdaisland/component_example.git
git checkout ep26-start