@@ -7,7 +7,7 @@ This is primarily a design pattern with a few helper functions. It can
7
7
be seen as a style of dependency injection using immutable data
8
8
structures.
9
9
10
-
10
+ See the [ video from Clojure/West 2014 ] ( https://www.youtube.com/watch?v=13cmHf_kt-Q ) (YouTube, 40 minutes)
11
11
12
12
13
13
## Releases and Dependency Information
@@ -44,7 +44,7 @@ structures.
44
44
## Dependencies and Compatibility
45
45
46
46
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 .
48
48
49
49
'Component' uses my [ dependency] library.
50
50
@@ -54,10 +54,10 @@ I have successfully tested 'Component' with Clojure versions
54
54
### API Stability
55
55
56
56
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.
58
58
59
59
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 .
61
61
62
62
63
63
@@ -203,8 +203,9 @@ To create a component, define a Clojure record that implements the
203
203
; ; component and release any external resources it has
204
204
; ; acquired.
205
205
(.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 )))
208
209
```
209
210
210
211
Optionally, provide a constructor function that takes arguments for
@@ -216,8 +217,8 @@ runtime state blank.
216
217
(map->Database {:host host :port port}))
217
218
```
218
219
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.
221
222
222
223
``` clojure
223
224
(defn get-user [database username]
@@ -326,8 +327,8 @@ Using the same example:
326
327
; ; \- Keys in the ExampleComponent record
327
328
```
328
329
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
331
332
the component) to start the components in the correct order.
332
333
333
334
Before starting each component, the system will ` assoc ` its
@@ -343,6 +344,11 @@ as if by:
343
344
(start))
344
345
```
345
346
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
+
346
352
It doesn't matter * when* you associate dependency metadata on a
347
353
component, as long as it happens before you call ` start ` . If you know
348
354
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:
353
359
354
360
(defrecord AnotherSystem [component-a component-b component-c])
355
361
356
- (defn another-component []
362
+ (defn another-component [] ; constructor
357
363
(component/using
358
364
(map->AnotherComponent {})
359
365
[:component-a :component-b ]))
0 commit comments