Liking cljdoc? Tell your friends :D

hara.core.component


all-dependenciesclj

(all-dependencies m)

gets all dependencies for long form

(all-dependencies {1 #{4 2} 2 #{3} 3 #{5} 4 #{} 5 #{6} 6 #{}}) => {1 #{2 3 4 5 6} 2 #{3 5 6} 3 #{5 6} 4 #{} 5 #{6} 6 #{}}

(-> (long-form {:model [identity] :ids [[identity]] :traps [[identity] [:model {:as :raw}] [:ids {:type :element :as :id}]] :entry [identity :model :ids] :nums [[{:expose :id}] :traps] :model-tag [{:expose :tag :setup identity} :model]}) get-dependencies all-dependencies) => {:model #{}, :ids #{}, :traps #{:ids :model}, :entry #{:ids :model}, :nums #{:ids :traps :model}, :model-tag #{:model}}

gets all dependencies for long form

(all-dependencies
 {1 #{4 2}
  2 #{3}
  3 #{5}
  4 #{}
  5 #{6}
  6 #{}})
=> {1 #{2 3 4 5 6}
    2 #{3 5 6}
    3 #{5 6}
    4 #{}
    5 #{6}
    6 #{}}

(-> (long-form {:model   [identity]
                :ids     [[identity]]
                :traps   [[identity] [:model {:as :raw}] [:ids {:type :element :as :id}]]
                :entry   [identity :model :ids]
                :nums    [[{:expose :id}] :traps]
               :model-tag  [{:expose :tag
                              :setup identity}  :model]})
    get-dependencies
    all-dependencies)
=> {:model #{},
    :ids #{},
    :traps #{:ids :model},
    :entry #{:ids :model},
    :nums #{:ids :traps :model},
    :model-tag #{:model}}
raw docstring

arrayclj

(array {:keys [constructor]} config)

creates an array of components

(def recs (start (array {:constructor map->Database} [{:id 1} {:id 2}]))) (count (seq recs)) => 2 (first recs) => (just {:id 1 :status "started"})

creates an array of components

(def recs (start (array {:constructor map->Database} [{:id 1} {:id 2}])))
(count (seq recs)) => 2
(first recs) => (just {:id 1 :status "started"})
raw docstring

array?clj

(array? x)

checks if object is a component array

(array? (array map->Database [])) => true

checks if object is a component array

(array? (array map->Database []))
=> true
raw docstring

component?clj

(component? x)

checks if an instance extends IComponent

(component? (Database.)) => true

checks if an instance extends IComponent

(component? (Database.))
=> true
raw docstring

constructorclj

(constructor x)

returns the constructor from topology

returns the constructor from topology
raw docstring

get-dependenciesclj

(get-dependencies full-topology)

get dependencies for long form (-> (long-form {:model [identity] :ids [[identity]] :traps [[identity] [:model {:as :raw}] [:ids {:type :element :as :id}]] :entry [identity :model :ids] :nums [[{:expose :id}] :traps] :model-tag [{:expose :tag :setup identity} :model]}) get-dependencies) => {:model #{}, :ids #{}, :traps #{:ids :model}, :entry #{:ids :model}, :nums #{:traps}, :model-tag #{:model}}

get dependencies for long form
 (-> (long-form {:model   [identity]
                 :ids     [[identity]]
                 :traps   [[identity] [:model {:as :raw}] [:ids {:type :element :as :id}]]
                 :entry   [identity :model :ids]
                 :nums    [[{:expose :id}] :traps]
                 :model-tag  [{:expose :tag
                               :setup identity}  :model]})
     get-dependencies)
=> {:model #{},
     :ids #{},
     :traps #{:ids :model},
     :entry #{:ids :model},
     :nums #{:traps},
     :model-tag #{:model}}
raw docstring

get-exposedclj

(get-exposed full-topology)

get exposed keys for long form (-> (long-form {:model [identity] :ids [[identity]] :traps [[identity] [:model {:as :raw}] [:ids {:type :element :as :id}]] :entry [identity :model :ids] :nums [[{:expose :id}] :traps] :model-tag [{:expose :tag :setup identity} :model]}) get-exposed) => [:nums :model-tag]

get exposed keys for long form
 (-> (long-form {:model   [identity]
                 :ids     [[identity]]
                 :traps   [[identity] [:model {:as :raw}] [:ids {:type :element :as :id}]]
                 :entry   [identity :model :ids]
                 :nums    [[{:expose :id}] :traps]
                 :model-tag  [{:expose :tag
                               :setup identity}  :model]})
     get-exposed)
=> [:nums :model-tag]
raw docstring

long-formclj

(long-form topology)

converts entire topology to long form

(long-form {:db [identity] :count [{:expose :count} :db]}) => (contains-in {:db {:compile :single, :type :build, :constructor fn?, :import {}, :dependencies ()}, :count {:compile :single, :type :expose, :in :db, :function :count, :dependencies [:db]}})

converts entire topology to long form

(long-form {:db [identity]
            :count [{:expose :count} :db]})
=> (contains-in {:db {:compile :single,
                      :type :build,
                      :constructor fn?,
                      :import {},
                      :dependencies ()},
                 :count {:compile :single,
                        :type :expose,
                         :in :db,
                         :function :count,
                         :dependencies [:db]}})
raw docstring

long-form-entryclj

(long-form-entry [desc & args])

converts short form entry into long form

(long-form-entry [{:constructor :identity :initialiser :identity}]) => {:type :build :compile :single :constructor :identity :initialiser :identity :import {}, :dependencies ()}

(long-form-entry [[identity]]) => (contains {:compile :array, :type :build, :constructor fn? :import {}, :dependencies ()})

(long-form-entry [[identity] [:model {:as :raw}] [:ids {:type :element :as :id}]]) => (contains {:compile :array, :type :build :constructor fn? :import {:model {:type :single, :as :raw}, :ids {:type :element, :as :id}}, :dependencies [:model :ids]})

converts short form entry into long form

(long-form-entry [{:constructor :identity
                   :initialiser :identity}])
=> {:type :build
    :compile :single
    :constructor :identity
    :initialiser :identity
    :import {}, :dependencies ()}

(long-form-entry [[identity]])
=> (contains {:compile :array,
              :type :build,
              :constructor fn?
              :import {},
              :dependencies ()})

(long-form-entry [[identity] [:model {:as :raw}] [:ids {:type :element :as :id}]])
=> (contains {:compile :array,
              :type :build
              :constructor fn?
              :import {:model {:type :single, :as :raw},
                       :ids {:type :element, :as :id}},
              :dependencies [:model :ids]})
raw docstring

long-form-importsclj

(long-form-imports args)

converts short form imports to long form

(long-form-imports [:db [:file {:as :fs}]]) => {:db {:type :single, :as :db}, :file {:type :single, :as :fs}}

(long-form-imports [[:ids {:type :element :as :id}]]) => {:ids {:type :element, :as :id}}

converts short form imports to long form

(long-form-imports [:db [:file {:as :fs}]])
=> {:db   {:type :single, :as :db},
    :file {:type :single, :as :fs}}

(long-form-imports [[:ids {:type :element :as :id}]])
=> {:ids {:type :element, :as :id}}
raw docstring

perform-hooksclj

(perform-hooks component functions hook-ks)

perform hooks before main function

(perform-hooks (Database.) {:init (fn [x] 1)} [:init]) => 1

perform hooks before main function

(perform-hooks (Database.)
               {:init (fn [x] 1)}
               [:init])
=> 1
raw docstring

primitive?clj

(primitive? x)

checks if a component is a primitive type

(primitive? 1) => true

(primitive? {}) => false

checks if a component is a primitive type

(primitive? 1) => true

(primitive? {}) => false
raw docstring

propertiesclj

(properties component)

returns properties of the system

(properties (Database.)) => {}

(properties (Filesystem.)) => {:hello "world"}

returns properties of the system

(properties (Database.)) => {}

(properties (Filesystem.)) => {:hello "world"}
raw docstring

startclj

(start component)
(start component {:keys [setup hooks] :as opts})

starts a component/array/system

(start (Database.)) => {:status "started"}

starts a component/array/system

(start (Database.))
=> {:status "started"}
raw docstring

start-arrayclj

(start-array carr)

starts an array of components

starts an array of components
raw docstring

start-systemclj

(start-system system)

starts a system (->> (system {:models [[identity] [:files {:type :element :as :fs}]] :files [[identity]]} {:models [{:m 1} {:m 2}] :files [{:id 1} {:id 2}]}) start-system (into {})) => (contains-in {:models [{:m 1, :fs {:id 1}} {:m 2, :fs {:id 2}}], :files [{:id 1} {:id 2}]})

starts a system
(->> (system {:models [[identity] [:files {:type :element :as :fs}]]
              :files  [[identity]]}
             {:models [{:m 1} {:m 2}]
              :files  [{:id 1} {:id 2}]})
     start-system
     (into {}))
=> (contains-in {:models [{:m 1,
                           :fs {:id 1}}
                         {:m 2,
                           :fs {:id 2}}],
                 :files [{:id 1} {:id 2}]})
raw docstring

started?clj

(started? component)

checks if a component has been started

(started? 1) => true

(started? {}) => false

(started? (start {})) => true

(started? (Database.)) => false

(started? (start (Database.))) => true

(started? (stop (start (Database.)))) => false

checks if a component has been started

(started? 1)
=> true

(started? {})
=> false

(started? (start {}))
=> true

(started? (Database.))
=> false

(started? (start (Database.)))
=> true

(started? (stop (start (Database.))))
=> false
raw docstring

stopclj

(stop component)
(stop component {:keys [teardown hooks] :as opts})

stops a component/array/system

(stop (start (Database.))) => {}

stops a component/array/system

(stop (start (Database.))) => {}
raw docstring

stop-arrayclj

(stop-array carr)

stops an array of components

stops an array of components
raw docstring

stop-systemclj

(stop-system system)

stops a system (stop-system (start-system (system {:model [identity] :ids [[identity]] :traps [[identity] [:model {:as :raw}] [:ids {:type :element :as :id}]] :entry [identity :model :ids] :nums [[{:expose :id}] :traps] :model-tag [{:expose :tag :setup identity} :model]} {:model {:tag :barbie} :ids [1 2 3 4 5] :traps [{} {} {} {} {}] :entry {}}))) => {:model {:tag :barbie}, :ids [1 2 3 4 5], :traps [{} {} {} {} {}], :entry {}}

stops a system
(stop-system
 (start-system
  (system {:model   [identity]
           :ids     [[identity]]
           :traps   [[identity] [:model {:as :raw}] [:ids {:type :element :as :id}]]
           :entry   [identity :model :ids]
           :nums    [[{:expose :id}] :traps]
           :model-tag  [{:expose :tag
                         :setup identity}  :model]}
         {:model {:tag :barbie}
           :ids   [1 2 3 4 5]
           :traps [{} {} {} {} {}]
           :entry {}})))
=>  {:model {:tag :barbie}, :ids [1 2 3 4 5], :traps [{} {} {} {} {}], :entry {}}
raw docstring

stopped?clj

(stopped? component)

checks if a component has been stopped

(stopped? 1) => false

(stopped? {}) => true

(stopped? (start {})) => false

(stopped? (Database.)) => true

(stopped? (start (Database.))) => false

(stopped? (stop (start (Database.)))) => true

checks if a component has been stopped

(stopped? 1)
=> false

(stopped? {})
=> true

(stopped? (start {}))
=> false

(stopped? (Database.))
=> true

(stopped? (start (Database.)))
=> false

(stopped? (stop (start (Database.))))
=> true
raw docstring

systemclj

(system topology config)
(system topology config {:keys [partial? tag display] :as opts})

creates a system of components

;; The topology specifies how the system is linked (def topo {:db [map->Database] :files [[map->Filesystem]] :catalogs [[map->Catalog] [:files {:type :element :as :fs}] :db]})

;; The configuration customises the system (def cfg {:db {:type :basic :host "localhost" :port 8080} :files [{:path "/app/local/1"} {:path "/app/local/2"}] :catalogs [{:id 1} {:id 2}]})

;; system will build it and calling start initiates it (def sys (-> (system topo cfg) start))

;; Check that the :db entry has started (:db sys) => (just {:status "started", :type :basic, :port 8080, :host "localhost"})

;; Check the first :files entry has started (-> sys :files first) => (just {:status "started", :path "/app/local/1"})

;; Check that the second :store entry has started (->> sys :catalogs second) => (contains-in {:id 2 :status "started" :db {:status "started", :type :basic, :port 8080, :host "localhost"} :fs {:path "/app/local/2", :status "started"}})

creates a system of components

;; The topology specifies how the system is linked
(def topo {:db        [map->Database]
           :files     [[map->Filesystem]]
           :catalogs  [[map->Catalog] [:files {:type :element :as :fs}] :db]})

;; The configuration customises the system
(def cfg  {:db     {:type :basic
                    :host "localhost"
                    :port 8080}
           :files [{:path "/app/local/1"}
                   {:path "/app/local/2"}]
           :catalogs [{:id 1}
                      {:id 2}]})

;; `system` will build it and calling `start` initiates it
(def sys (-> (system topo cfg) start))

;; Check that the `:db` entry has started
(:db sys)
=> (just {:status "started",
          :type :basic,
          :port 8080,
          :host "localhost"})

;; Check the first `:files` entry has started
(-> sys :files first)
=> (just {:status "started",
          :path "/app/local/1"})

;; Check that the second `:store` entry has started
(->> sys :catalogs second)
=> (contains-in {:id 2
                 :status "started"
                 :db {:status "started",
                      :type :basic,
                      :port 8080,
                      :host "localhost"}
                 :fs {:path "/app/local/2", :status "started"}})
raw docstring

system-deportclj

(system-deport component import)

deports a component from the system

deports a component from the system
raw docstring

system-exposeclj

(system-expose _ system {:keys [in function] :as opts})

exposes a component into the system

exposes a component into the system
raw docstring

system-importclj

(system-import component system import)

imports a component into the system

imports a component into the system
raw docstring

system-stringclj

(system-string sys)

returns the system for display

(system-string (system {:a [identity] :b [identity]} {:a 1 :b 2} {:tag "happy"})) => "#happy {:a 1, :b 2}"

returns the system for display

(system-string (system {:a [identity]
                        :b [identity]}
                       {:a 1 :b 2}
                       {:tag "happy"}))
=> "#happy {:a 1, :b 2}"
raw docstring

system?clj

(system? x)

checks if object is a component system

(system? (system {} {})) => true

checks if object is a component system

(system? (system {} {}))
=> true
raw docstring

valid-subcomponentsclj

(valid-subcomponents full-topology keys)

returns only the components that will work (for partial systems)

(valid-subcomponents (long-form {:model [identity] :tag [{:expose :tag} :model] :kramer [identity :tag]}) [:model]) => [:model :tag]

returns only the components that will work (for partial systems)

(valid-subcomponents
 (long-form {:model  [identity]
             :tag    [{:expose :tag} :model]
             :kramer [identity :tag]})
 [:model])
=> [:model :tag]
raw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close