(inject-cofx id)
(inject-cofx id value)
Returns an interceptor which adds to a context's
:coeffects
.
coeffects
are the input resources required by an event handler
to perform its job. The two most obvious ones are db
and event
.
But sometimes a handler might need other resources.
Perhaps a handler needs a random number or a GUID or the current datetime. Perhaps it needs access to the connection to a DataScript database.
If the handler directly access these resources, it stops being as pure. It immedaitely becomes harder to test, etc.
So the necessary resources are "injected" into the coeffect
(map)
given the handler.
Given an id
, and an optional value, lookup the registered coeffect
handler (previously registered via reg-cofx
) and it with two arguments:
the current value of :coeffect
and, optionally, the value. The registered handler
is expected to return a modified coeffect.
Returns an interceptor which adds to a `context's` `:coeffects`. `coeffects` are the input resources required by an event handler to perform its job. The two most obvious ones are `db` and `event`. But sometimes a handler might need other resources. Perhaps a handler needs a random number or a GUID or the current datetime. Perhaps it needs access to the connection to a DataScript database. If the handler directly access these resources, it stops being as pure. It immedaitely becomes harder to test, etc. So the necessary resources are "injected" into the `coeffect` (map) given the handler. Given an `id`, and an optional value, lookup the registered coeffect handler (previously registered via `reg-cofx`) and it with two arguments: the current value of `:coeffect` and, optionally, the value. The registered handler is expected to return a modified coeffect.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close