Liking cljdoc? Tell your friends :D

com.biffweb.core

The main framework/inversion-of-control code for Biff.

Contains functions for starting/stopping Biff applications and for validating
data that needs to cross module/component boundaries.


GLOSSARY

system map:
  A map of namespaced keys that contains the state of the running Biff
  application.

modules:
  A collection of maps that together define your application's functionality.

components:
  A sequence of functions that start stateful resources and do other
  initialization needed by your application.

register

view source

(register schemas)

Merges a map of Malli schemas into Biff's global schema registry.

  (biff.core/register {:person/display-name :string
                       :person/age          :int})

Registered schemas are used by biff.core/validate.

get-registry

view source

(get-registry)

Returns all schemas that have been passed to biff.core/register.

(biff.core/get-registry)
=> {:person/display-name :string
    :person/age          :int}

validate

view source

(validate m & {:keys [required extra-schema]})

Throws an AssertionError if any values in m don't match the registered
schemas for their key.

  (biff.core/register {:person/age :int})
  (biff.core/validate {:person/age "three"})
  ; =>
  ; (err) `:person/age "three"` is invalid: should be an integer

:required
  A sequence of keys. Throws an error if any of these aren't present in m.

:extra-schema
  A map of Malli schemas. Can be used to define schema without modifying the
  global registry by calling biff.core/register.

For convenience, m can be a sequence of maps instead of a single map.

start

view source

(start initial-system modules-var components)

Starts a Biff application and returns the system map.

  (def modules [...])
  (def components [...])
  (biff.core/start {} #'modules components)

Calls any :biff.core/init functions in modules and merges with initial-system
(the latter takes precedence). Then passes the system map through each
component.

:biff.core/init is a function that receives the modules var, aggregates keys
from other modules and/or initializes other values as needed, and inserts the
result into the system map. For values that should be updated when
modules-var is updated (without restarting the application), :biff.core/init
can wrap them with a function that's memoized based on the value of
modules-var:

  (def get-foo
    (memoize
     (fn [modules]
       (aggregate-foos
        (keep :example/foo modules)))))

  {:biff.core/init
   (fn [modules-var]
     {:example/get-foo #(get-foo @modules-var)})}

Each component is a function that receives the system map, starts stateful
resources or does other initialization as needed, and returns an updated
system map. Components can add stop functions (zero-arg functions that stop a
stateful resource) to the end of the :biff.core/stop vector. :biff/stop is
also recognized for backwards compatibility.

Uses biff.core/validate to ensure that keys in modules, keys returned by
:biff.core/init, and keys returned by components are valid.

stop

view source

(stop system)

Stops a Biff application.

Calls the :biff.core/stop functions from system in reverse order.

Can you improve this documentation?Edit on GitHub

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close