File tree Expand file tree Collapse file tree 1 file changed +37
-1
lines changed Expand file tree Collapse file tree 1 file changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ project.
25
25
26
26
WARNING: This documentation assumes knowledge of Clojure.
27
27
28
- == Setup
28
+ == Project Setup
29
29
30
30
This section will cover setting up a new Duct project. You'll first need
31
31
to ensure that the
@@ -270,3 +270,39 @@ $ NAME=Clojurist duct --main
270
270
✓ Initiating system...
271
271
Hello Clojurist
272
272
----
273
+
274
+ === References
275
+
276
+ A Duct system can have multiple components, and components can
277
+ communicate via references, which are divided into *refs* and
278
+ *refsets*. A ref references exactly one other component; a refset
279
+ references zero or more components.
280
+
281
+ To demonstrate how refs work, we'll divide our '`Hello World`'
282
+ application into two functions.
283
+
284
+ [,clojure]
285
+ ----
286
+ (ns tutorial.print)
287
+
288
+ (defn printer [{:keys [prefix]}]
289
+ (partial println prefix))
290
+
291
+ (defn hello [{:keys [name output]}]
292
+ (output "Hello" name))
293
+ ----
294
+
295
+ The `printer` component returns a function that prints its arguments
296
+ with a custom prefix. The `hello` component takes a `:output` option
297
+ that it uses to output a message. In order to connect these two
298
+ components in the `duct.edn` file, we use the `#ig/ref` data reader.
299
+
300
+ [,clojure]
301
+ ----
302
+ {:system
303
+ {:tutorial.print/printer
304
+ {:prefix ">>"}
305
+ :tutorial.print/hello
306
+ {:name "World"
307
+ :output #ig/ref :tutorial.print/printer}}}
308
+ ----
You can’t perform that action at this time.
0 commit comments