Giter VIP home page Giter VIP logo

modular.co-dependency's Introduction

juxt.modular/co-dependency

Releases and Dependency Information

[juxt.modular/co-dependency "0.2.0"]

Usage

Add co-dependency to your project dependencies

(defproject your-project "your-version"
   ...
   :dependencies [[juxt.modular/co-dependency "0.2.0"]]
   ...
   )

Add component and co-dependency to your ns:

(ns your-app-ns
  (:require [com.stuartsierra.component :refer (using)]
            [modular.component.co-dependency :refer (co-using)]))

Define your system

Same as you do with stuartsierra/component lib but adding co-dependencies with co-dependency/co-using fn In this case :b depends on :a and :a co-depends on :b

(defn system-1 []
  (map->System1 {:a (-> (component-a)
                        (co-using [:b]))
                 :b (-> (component-b)
                        (using [:a]))
                 :c (-> (component-c)
                        (using [:a :b]))
                 :d (-> (component-d)
                        (using {:b :b :c :c}))
                 :e (component-e)})

Start your system

(def system-started-with-co-deps (co-dependency/start-system (system-1)))

Retrieving co-dependencies values

(def a (-> system-started-with-co-deps :a))
(def a-from-b (:a @(-> system-started-with-co-deps :a :b)))
;; checking identity equality
(assert (= a a-from-b))

Using stuartsierra reloaded workflow

If you use stuartsierra "reloaded" workflow then update original stuartsierra dev/start function by:

(defn start
  "Starts the current development system."
  []
  (alter-var-root #'system co-dependency/start-system))

Do you need more help?

Follow the test provided to learn how to use it :)

Drawbacks

In contrast with normal dependencies that you get using clojure map functions

(:dependency-key component)
;;=> dependency

when you want to retrieve a co-dependency you need to deref the co-dependency value

@(:co-dependency-key component)
;;=> co-dependency

License

Copyright © 2014 Juan Antonio Ruz (juxt.pro)

Distributed under the Eclipse Public License, the same as Clojure

modular.co-dependency's People

Contributors

malcolmsparks avatar pleasetrythisathome avatar tangrammer avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.