(configure component config)(configure component config merge-fn)Recursively merge config map into component using merge-fns as necessary. Maps are recursively merged. Sets, vectors and lists are non-recursively concatenated.
This behavior can be overridden with merge-fns, which should match the structure of config and value. A merge function takes two arguments: the current value, and the configured value (respectively) and should return the final, resolved value.
Example:
user> (amalgam/configure {:a [1] :b {:c [2]}}
{:a [10] :b {:c [20] :d 30}}
{:b {:c amalgam/overwrite}})
{:a [1 10], :b {:c [20], :d 30}}
Recursively merge config map into component using merge-fns as necessary. Maps are recursively
merged. Sets, vectors and lists are non-recursively concatenated.
This behavior can be overridden with merge-fns, which should match the structure of config and
value. A merge function takes two arguments: the current value, and the configured value
(respectively) and should return the final, resolved value.
Example:
```clojure
user> (amalgam/configure {:a [1] :b {:c [2]}}
{:a [10] :b {:c [20] :d 30}}
{:b {:c amalgam/overwrite}})
{:a [1 10], :b {:c [20], :d 30}}
```(make-component-fn & {:keys [start stop]})Make a component constructor that takes options as keyword args and returns a component.
After this component has been started, stopping it resets it back to the options map. In other words,
(let [make-component (make-component-fn ...)
c (make-component ...)]
(assert (identical? c (component/stop (component/start c)))))
start — (optional) a single argument function taking the options and returning a new
instance of the component. The return value of start should be able to take metadata.stop — (optional) a single argument function taking the component and releasing resources.
stop is side-effecting and its return value is ignored.Example:
(def temp-file
(amalgam/make-component-fn
:start (fn [this] (assoc this :file (io/file (:path this))))
:stop (fn [this] (io/delete-file (:file this) true))))
(def my-system (component/system-map :scratch-file (temp-file :path "/tmp/scratch")))
Make a component constructor that takes options as keyword args and returns a component.
After this component has been started, stopping it resets it back to the options map. In other
words,
```clojure
(let [make-component (make-component-fn ...)
c (make-component ...)]
(assert (identical? c (component/stop (component/start c)))))
```
- **`start`** — (optional) a single argument function taking the options and returning a new
instance of the component. The return value of `start` should be able to take metadata.
- **`stop`** — (optional) a single argument function taking the component and releasing resources.
`stop` is side-effecting and its return value is ignored.
Example:
```clojure
(def temp-file
(amalgam/make-component-fn
:start (fn [this] (assoc this :file (io/file (:path this))))
:stop (fn [this] (io/delete-file (:file this) true))))
(def my-system (component/system-map :scratch-file (temp-file :path "/tmp/scratch")))
```(overwrite _v c)Resolve current and configuration values by always taking the configuration value.
Resolve current and configuration values by always taking the configuration value.
(run-system make-system read-config)(run-system make-system read-config merge-fns)Start a configured system and run it until the JVM exits.
make-system — no argument function returning a new systemread-config — no argument function returning the configuration map. The configuration map
should mirror the structure of the system.merge-fns (optional) — map mirroring the structure of both the system and configuration
maps that contains merge functions to resolve a final value from the current value and
configured value.Start a configured system and run it until the JVM exits. - **`make-system`** — no argument function returning a new system - **`read-config`** — no argument function returning the configuration map. The configuration map should mirror the structure of the system. - **`merge-fns`** (optional) — map mirroring the structure of both the system and configuration maps that contains merge functions to resolve a final value from the current value and configured value. See [[configure]] [[start-system]]
(start-system make-system read-config)(start-system make-system read-config merge-fns)Construct, configure, then start a system.
make-system — no argument function returning a new systemread-config — no argument function returning the configuration map. The configuration map
should mirror the structure of the system.merge-fns (optional) — map mirroring the structure of both the system and configuration
maps that contains merge functions to resolve a final value from the current value and
configured value.Example:
user> (amalgam/start-system #(component/system-map :component (map->Component {:foo :bar}))
(constantly {:component {:foo :baz}})
{:component {:foo amalgam/overwrite}})
{:component {:foo :baz}}
See configure
Construct, configure, then start a system.
- **`make-system`** — no argument function returning a new system
- **`read-config`** — no argument function returning the configuration map. The configuration map
should mirror the structure of the system.
- **`merge-fns`** (optional) — map mirroring the structure of both the system and configuration
maps that contains merge functions to resolve a final value from the current value and
configured value.
Example:
```clojure
user> (amalgam/start-system #(component/system-map :component (map->Component {:foo :bar}))
(constantly {:component {:foo :baz}})
{:component {:foo amalgam/overwrite}})
{:component {:foo :baz}}
```
See [[configure]]cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |