Skip to content

Instantly share code, notes, and snippets.

@ddellacosta
Last active August 29, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ddellacosta/07be4db31425f4827f1a to your computer and use it in GitHub Desktop.
Save ddellacosta/07be4db31425f4827f1a to your computer and use it in GitHub Desktop.
(ns my.namespace
(:require
[com.stuartsierra.component :as component]))
(defrecord ExampleComponent [options foo]
component/Lifecycle
(start [this]
(println ";; Starting ExampleComponent")
;; In the 'start' method, a component may assume that its
;; dependencies are available and have already been started.
(assoc this :foo "foo"))
(stop [this]
(println ";; Stopping ExampleComponent")
;; Likewise, in the 'stop' method, a component may assume that its
;; dependencies will not be stopped until AFTER it is stopped.
(dissoc this :foo)))
(defn example-component [config-options]
(map->ExampleComponent {:options config-options}))
(defn example-system [config-options]
(component/system-map
:app (component/using
(example-component config-options)
{})))
> (require '[com.stuartsierra.component :as component] '[my.namespace :as n] :reload)
> (def system (web-comp/example-system {}))
> (:app (component/start system))
#de.web.component.ExampleComponent{:options {}, :foo nil} ; no println, and map is not altered?
>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment