Code Monkey home page Code Monkey logo

Comments (5)

weavejester avatar weavejester commented on May 8, 2024

Why do you require :license to evaluate before :server? What does it do?

Also, do you know about prep-key and resolve-key?

from integrant.

d-t-w avatar d-t-w commented on May 8, 2024

My example is slightly contrived, but lets say I want the license state to evaluate first as it may cause the system initialisation to stop and I want to ensure the server (or other, possibly side-effecting sub-system) has not started prior.

prep-key and resolve-key relate to a single key, I'm interested in controlling the initialisation order of otherwise unrelated sub-parts of a system.

from integrant.

weavejester avatar weavejester commented on May 8, 2024

It sounds like you still have a dependency between :license and :server, but you're not interested in the data, just whether or not the initialization was valid.

You can set up automatic relations with prep-key. For example:

(defmethod ig/prep-key :app/server [_ opts]
  (assoc opts ::depends-on (ig/ref :app/license)))

You can use ig/refset to make it an optional dependency:

(defmethod ig/prep-key :app/server [_ opts]
  (assoc opts ::depends-on (ig/refset :app/license)))

from integrant.

d-t-w avatar d-t-w commented on May 8, 2024

Thanks James, I'm struggling to remember the usual cases but I expect generally there's an external, stateful co-dependency where I'm not interested in the data but do require a creation order within my system.

I'll give prep-key and/or refset a go, seems like that will work.

from integrant.

dimovich avatar dimovich commented on May 8, 2024

Interesting discussion. I usually tend to prefer the config approach as in @d-t-w 's initial message, so if you have to change the init order you don't have to change the code, but only the config. But in the case of a license, the prep-key seems like a good solution.

from integrant.

Related Issues (20)

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.