mount

arnout 2016-02-14T11:26:36.000393Z

@tolitius (or anyone interested), I am curious to know your opinion on https://github.com/aroemers/mount-lite/pull/5 :simple_smile:

dm3 2016-02-14T11:39:09.000395Z

hm, that seems like syntactic sugar on top of

(def ^dynamic *i* 10)

(defstate incrementer
  :start (let [i *i*] (fn [n] (+ n i)))
  :stop ...)

(with-redefs [*i* 20]
  (mount/start))
am I missing anything? Doesn't seem all that useful

arnout 2016-02-14T11:40:17.000396Z

True, though with-redefs is thread local

dm3 2016-02-14T11:40:41.000398Z

yep, hence the let in the start

arnout 2016-02-14T11:41:41.000399Z

No, that would not work, if the with-redefs in your example is done in another thread than where the the :start expression is executed.

dm3 2016-02-14T11:42:05.000400Z

well, in that case true

dm3 2016-02-14T11:42:19.000401Z

but I don't really see how that could happen

arnout 2016-02-14T11:42:32.000402Z

mount-lite supports parallel starting and stopping :simple_smile:

dm3 2016-02-14T11:42:44.000403Z

ok :simple_smile:

dm3 2016-02-14T11:42:52.000404Z

then alter-var-root? :simple_smile:

dm3 2016-02-14T11:43:26.000405Z

anyway, I don't see the value of bindings (in my limited world of using mount)

dm3 2016-02-14T11:43:45.000406Z

could you maybe describe what you're using them for?

arnout 2016-02-14T11:43:46.000407Z

Hmm, yes. Would be more stateful though, requiring an extra (global!) var and remembering to reset it after a (stop).

arnout 2016-02-14T11:45:07.000409Z

I'm not, currently :simple_smile: It was just an idea I had this morning.

arnout 2016-02-14T11:45:41.000410Z

I thought it would be a nice solution for having some DI and argument passing.

arnout 2016-02-14T11:46:49.000411Z

Good to know though, that you would not find it useful, thanks :simple_smile:

dm3 2016-02-14T11:48:00.000412Z

all my use cases were covered by using a config ns

dm3 2016-02-14T11:48:11.000413Z

and pulling values out of it in other defstates

dm3 2016-02-14T11:48:52.000414Z

IMHO neither component, nor mount should be present in libraries (except for an optional integration)

arnout 2016-02-14T11:52:42.000415Z

I see. And yes, I share that humble opinion.

2016-02-14T14:37:13.000417Z

Hi there, I have a (maybe simple minded) question on mount usage with regard to substitutions

2016-02-14T14:38:04.000418Z

I'm starting from the point of view that I might want to change behavior when I substitute some state, in particular for testing purposes

2016-02-14T14:38:34.000419Z

I don't see any obvious ways how mount would support that, am I right?

dm3 2016-02-14T14:43:17.000420Z

you substitute your state with something that you control, right? Something that would change the behaviour based on what you need in the test? E.g. mock database connection instead of a real one.

dm3 2016-02-14T14:43:29.000421Z

@schaueho: could you expand on the problem?

2016-02-14T14:47:56.000422Z

yes, e.g. my real db connection would be to a mongo db, but the mock db would then need quite different implementations

2016-02-14T14:48:44.000423Z

so, the real db has a "find-docs" function and the mock one, too, but obviously with quite different behavior (e.g. using atoms for the data storage)

dm3 2016-02-14T14:49:38.000424Z

then you need to mock your API

dm3 2016-02-14T14:50:25.000425Z

the functions in the NS, as seemingly you're not testing the mongo implementation but the things that use it

2016-02-14T14:54:55.000426Z

yes, that's what I was thinking

2016-02-14T15:01:23.000427Z

just to explain a bit, the send-sms example on the mount homepage was throwing me off a little

2016-02-14T15:03:04.000428Z

the substituted state looks like a normal object to be used by some function, whereas the substitute is a function

2016-02-14T15:03:45.000429Z

so I was wondering if the idea would be to have callables as states

dm3 2016-02-14T15:10:50.000430Z

not really

dm3 2016-02-14T15:11:07.000431Z

your state should be something that has a lifecycle

dm3 2016-02-14T15:11:40.000432Z

you can create a MongoUserDb and MockUserDb types that implement a UserDb protocol

dm3 2016-02-14T15:11:54.000433Z

and then substitute that

dm3 2016-02-14T15:12:04.000434Z

or you can just redef the functions directly

dm3 2016-02-14T15:12:53.000435Z

the problem here is that you need a different implementation

2016-02-14T15:13:05.000436Z

I would probably prefer protocols, but that way lies component

2016-02-14T15:13:29.000437Z

there are also some other smaller libraries to help with this particular problem

dm3 2016-02-14T15:14:15.000439Z

I usually do good old with-redefs :simple_smile:

2016-02-14T15:16:02.000441Z

with-redefs is fine for testing, but doesn't help with decoupling dependencies

2016-02-14T15:16:13.000442Z

but anyways, thanks for the feedback

arnout 2016-02-14T15:30:25.000443Z

@schaueho: Using a UserDb protocol as @dm3 suggests would be the way to go. The issue you describe is not solved by either component or mount. Protocols solve your issue, and are still a good thing :simple_smile: Mount still lets you use protocols, but you don't have to (as with Component you easily fall in the trap of putting everything in a protocol).

tolitius 2016-02-14T23:59:27.000002Z

@arnout: what would be an example of using the bindings idea in case a state is a resource?