Last active
August 29, 2015 14:26
-
-
Save ddellacosta/07be4db31425f4827f1a 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 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) | |
{}))) |
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
> (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