This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-02-08
Channels
- # aleph (2)
- # aws (1)
- # beginners (172)
- # boot (15)
- # cider (17)
- # clara (7)
- # cljs-dev (22)
- # cljsrn (12)
- # clojars (3)
- # clojure (110)
- # clojure-dev (5)
- # clojure-italy (13)
- # clojure-sanfrancisco (5)
- # clojure-spec (3)
- # clojure-uk (31)
- # clojurescript (110)
- # community-development (2)
- # cursive (16)
- # datomic (19)
- # docs (4)
- # emacs (49)
- # fulcro (24)
- # jobs (5)
- # keechma (2)
- # lein-figwheel (41)
- # leiningen (10)
- # luminus (4)
- # lumo (24)
- # mount (24)
- # numerical-computing (1)
- # off-topic (16)
- # om (4)
- # onyx (6)
- # parinfer (9)
- # planck (8)
- # re-frame (7)
- # reagent (6)
- # shadow-cljs (125)
- # sql (5)
- # test-check (9)
- # unrepl (6)
- # yada (5)
Do I understand correctly that to pass a parameter to a :start lifecycle function I need to specify it inside another defstate? or have the parameters definied in the namespace? no way to pass the argument to the function directly though?
@aleksander is it a command line argument?
no, just a configuration value
a port on which the web server is supposed to listen on
ideally I would like to pass that value when starting
usually you would create a config
state which reads a config file or reaches out to external configuration service (i.e. consul, etcd, ..)
then in other states that need config, such as port, you would do something similar to (config :port)
here is an example: https://github.com/tolitius/hubble
it reads config from consul: https://github.com/tolitius/hubble/blob/master/src/clj/hubble/env.clj#L30 but it could also simply read it from a local config file, since it just becomes a map when started
and here it reads a server port to start a server state: https://github.com/tolitius/hubble/blob/master/src/clj/hubble/server.clj#L44-L49
here is an example of reading a config from a file into a state: https://github.com/tolitius/stater/blob/master/smsio/src/app/conf.clj
and then starting a server with it: https://github.com/tolitius/stater/blob/master/smsio/src/app/www.clj#L20-L27
Thanks, I'll go through the examples tomorrow!
yes, main I was thinking of reading the configuration outside of a mount component
@aleksander
> I was thinking of reading the configuration outside of a mount component
if you really do not want to have a config component (why?) instead of (mount/start)
you could use (mount/start-with-args args)
where args is a map with arguments
I wanted to explicitly pass the port to the web server component as a parameter, not having it read from other component inside the :start function
but that doesn't seem to be mount way
you wouldn't/can't pass parameters to :start functions
the motivation would be to easier see the dependencies
> the motivation would be to easier see the dependencies
since mount start components in the order they are "used", you would always see config
as a dependency:
dev=> (require '[mount.tools.graph :as graph])
dev=> (graph/states-with-deps)
({:name "#'app.conf/config",
:order 1,
:status #{:started},
:deps #{}}
{:name "#'app.db/conn",
:order 2,
:status #{:started},
:deps #{"#'app.conf/config"}}
{:name "#'app.www/nyse-app",
:order 3,
:status #{:started},
:deps #{"#'app.conf/config"}}
{:name "#'app.example/nrepl",
:order 4,
:status #{:started},
:deps #{"#'app.www/nyse-app" "#'app.conf/config"}})