Skip to content

Commit dafe965

Browse files
author
Stuart Sierra
committed
Copy README & examples.clj from reverse-dependencies branch
Includes additional notes about `stop` not being the inverse of `start` and an example warning not to `dissoc` base fields from a record.
1 parent 030fe57 commit dafe965

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

README.md

+17-11
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ This is primarily a design pattern with a few helper functions. It can
77
be seen as a style of dependency injection using immutable data
88
structures.
99

10-
10+
See the [video from Clojure/West 2014](https://www.youtube.com/watch?v=13cmHf_kt-Q) (YouTube, 40 minutes)
1111

1212

1313
## Releases and Dependency Information
@@ -44,7 +44,7 @@ structures.
4444
## Dependencies and Compatibility
4545

4646
I have successfully tested 'Component' with Clojure versions
47-
1.4.0 and 1.5.1.
47+
1.4.0, 1.5.1, and 1.6.0.
4848

4949
'Component' uses my [dependency] library.
5050

@@ -54,10 +54,10 @@ I have successfully tested 'Component' with Clojure versions
5454
### API Stability
5555

5656
I will make an effort not to break backwards compability between
57-
releases at the same 0.N version, e.g. 0.2.X and 0.2.Y
57+
releases at the same 0.N version, e.g. 0.2.1 and 0.2.2.
5858

5959
Expect to find breaking changes between releases at different 0.N
60-
versions, e.g. 0.X and 0.Y.
60+
versions, e.g. 0.3.0 and 0.4.0.
6161

6262

6363

@@ -203,8 +203,9 @@ To create a component, define a Clojure record that implements the
203203
;; component and release any external resources it has
204204
;; acquired.
205205
(.close connection)
206-
;; Return the component, optionally modified.
207-
component))
206+
;; Return the component, optionally modified. Remember that if you
207+
;; dissoc one of a record's base fields, you get a plain map.
208+
(assoc component :connection nil)))
208209
```
209210

210211
Optionally, provide a constructor function that takes arguments for
@@ -216,8 +217,8 @@ runtime state blank.
216217
(map->Database {:host host :port port}))
217218
```
218219

219-
Define the functions implementing the behavior of the
220-
component to take the component itself as an argument.
220+
Define the functions implementing the behavior of the component to
221+
take an **instance** of the component as an argument.
221222

222223
```clojure
223224
(defn get-user [database username]
@@ -326,8 +327,8 @@ Using the same example:
326327
;; \- Keys in the ExampleComponent record
327328
```
328329

329-
The system map provides its own implementations of the Lifecycle
330-
protocol which use this dependency information (stored as metadata on
330+
The system map provides its own implementation of the Lifecycle
331+
protocol which uses this dependency information (stored as metadata on
331332
the component) to start the components in the correct order.
332333

333334
Before starting each component, the system will `assoc` its
@@ -343,6 +344,11 @@ as if by:
343344
(start))
344345
```
345346

347+
Stop a system by calling the `stop` method on it. This will stop each
348+
component, in *reverse* dependency order, and then re-assoc the
349+
dependencies of each component. **Note:** `stop` is not the exact
350+
inverse of `start`; component dependencies will still be associated.
351+
346352
It doesn't matter *when* you associate dependency metadata on a
347353
component, as long as it happens before you call `start`. If you know
348354
the names of all the components in your system in advance, you could
@@ -353,7 +359,7 @@ choose to add the metadata in the component's constructor:
353359

354360
(defrecord AnotherSystem [component-a component-b component-c])
355361

356-
(defn another-component []
362+
(defn another-component [] ; constructor
357363
(component/using
358364
(map->AnotherComponent {})
359365
[:component-a :component-b]))

dev/examples.clj

+3-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@
5050
;; component and release any external resources it has
5151
;; acquired.
5252
(.close connection)
53-
;; Return the component, optionally modified.
54-
component))
53+
;; Return the component, optionally modified. Remember that if you
54+
;; dissoc one of a record's base fields, you get a plain map.
55+
(assoc component :connection nil)))
5556

5657
;; Optionally, provide a constructor function that takes in
5758
;; the essential configuration parameters of the component,

0 commit comments

Comments
 (0)