A donut.system
plugin for transforming declarative definitions into components.
Alpha
This library is a proof of concept. Use at your own risk. Issues and PRs are welcome!
Latest version: 0.0.14
(tag v0.0.14
)
xyz.psyclyx/pastry {:mvn/version "0.0.14"}
[xyz.psyclyx/pastry "0.0.14"]
pastry-plugin
finds and transforms component definitions, allowing you to define components with simple data instead of full donut.system
maps.
Snippets in this section assume the following requires:
(require
'[donut.system :as donut]
'[psyclyx.pastry :as pastry])
By default, pastry
transforms maps containing a ::pastry/type
key. Component creation logic is defined with a defmethod
for pastry/->component
.
(defmethod pastry/->component :my-app/greeter
[{:keys [greeting]}]
{::donut/start (constantly greeting)})
(def system
{::donut/plugins [pastry/pastry-plugin]
::donut/defs
{:app {:greeter {::pastry/type :my-app/greeter
:greeting "Hello, pastry!"}}}})
(-> (donut/signal system ::donut/start)
(get-in [::donut/instances :app :greeter]))
;; => "Hello, pastry!"
For more flexibility, the target predicate and transformation function can be configured at the system level.
(def system
{::donut/plugins [pastry/pastry-plugin]
::pastry/target? string?
::pastry/->component (fn [s] {::donut/start (constantly (count s))})
::donut/defs
{:app {:string-length "a string definition"}}})
(-> (donut/signal system ::donut/start)
(get-in [::donut/instances :app :string-length]))
;; => 19
Issues and pull requests welcome!
This is free and unencumbered software released into the public domain.
Can you improve this documentation?Edit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close