tolitius / mount

managing Clojure and ClojureScript app state since (reset)
Eclipse Public License 1.0
1.23k stars 89 forks source link

Add back possibility to have a function as a state value #21

Closed aroemers closed 8 years ago

aroemers commented 8 years ago

Issue #20 adds a lot of flexibility, but removed the possibility to have a function as a state value. This patch brings that back.

tolitius commented 8 years ago

I believe you already added a "possibility to have a function as a state value" with the power of thought rather than a pull request :) Do you still see a need for this?

tolitius commented 8 years ago

ah.. I see what you mean, good catch! I did not want to push it myself since it is your idea, but I'd like to rename things a bit and I'll merge it.

tolitius commented 8 years ago

@aroemers: gave it a bit more thought. why do we need trampoline at all? since it is always `(fn [] ~value), we can always just call that fn.

here is where I am coming from.

It will be consistent with the current API: no additional syntax need for an fn-state corner case, and will actually simplify #18 by a lot.

aroemers commented 8 years ago

Got to sleep now, but quick response, consider this case:

(defn- start-fn [] ...)

(defstate foo :start start-fn)
tolitius commented 8 years ago

@aroemers: you mean something like this being used in another namespace?

aroemers commented 8 years ago

@tolitius Not really, what I meant is that start-fn above is called when starting the state. So, to complete my example:

(defn- start-fn [] "bar")

(defstate foo :start start-fn)

(mount/start)

foo
;=> "bar"

Of course, maybe it is just a trade-off, and functions should not be supported in this way, only forms. Above example would only need this change to work without a trampoline:

(defstate foo :start (start-fn))
tolitius commented 8 years ago

@aroemers I'd prefer a simple syntax with the understanding of (f) vs. f

the idea was that state's :start will be "invoked" on (mount/start). values came later from @xhh and your contributions :)

aroemers commented 8 years ago

@tolitius Alright, I respect that choice. Closing this one then.