Hey, thanks for responding. My responses are inlined.

On Thu, May 1, 2014 at 1:34 AM, Atamert Ölçgen <mu...@muhuk.com> wrote:

> I am not an expert on Component. But AFAIK it is not for managing mutable
> state but for assembling and configuring components, that might or might
> not be mutable themselves, in an immutable fashion.
>

Agreed, this is what I've found. Component isn't for the use case of state
changes between components.

I'm actually looking at Datascript
<https://github.com/tonsky/datascript>as a way of managing internal,
runtime, changing RIA state.



> However from what I can understand, your component-a has an atom, like:
>
>      (->component-a (atom something))
>
> Which should be OK. I mean it shouldn't matter from which path you are
> accessing this atom.
>
> Can you share the constructor/definition of the components?
>

I can't really share actual client code. But the system definition in
fig.1. pretty much describes how the real components are stitched together.


Also, have you tried confirming that only one :a is instantiated?
>

That one *:a* is not the same instance throughout all the dependant
components. Seems that it's the [*:core :a*] bit that's passed to all the
components in the *'start* *'stop* functions. I say this, because when one
of my dependant components updated an atom in it's own [*:local :a*], it
was [*:core :a*] that reflected that change.


On Wed, Apr 30, 2014 at 9:13 PM, Timothy Washington <twash...@gmail.com>wrote:
>
>> Hi all,
>>
>> I'm having a weird state problem with 
>> Component<https://github.com/stuartsierra/component>.
>> Let's say I have a system component, like in fig.1. Starting / stopping and
>> loading state is fine.
>> However, let's say I have 2 other components (:updater , :reader) that
>> use component :a. This is the problem that occurs.
>>
>>    1. When *:updater*, modifies an atom in *:a*, that change appears in
>>    path [*:core :a*], not path [*:updater :a*] or [*:a*].
>>    2. Because of the abouve, when *:reader* goes to it's local path [
>>    *:reader :a*] to read that change, it doesn't see those
>>    modifications.
>>    3. Using this scheme, *:a* is duplicated 4 times, in the system map.
>>    However, the modifications only appear in path [*:core :a*]. Thus
>>    :reader is unable to access it (it's local [*:a*] is unchanged).
>>
>>
>> (def system-components [:a :updater :reader])
>>
>> (defrecord Core [env] component/Lifecycle
>>   (start [this] ...)
>>   (stop [this] ...))
>>
>> (defn component-core [env]
>>
>>   (component/system-map
>>    :a (component/using
>>           (ca/component-a env)
>>           {})
>>    :updater (component/using
>>          (cs/component-updater env)
>>          {:a :a})
>>    :reader(component/using
>>          (cs/component-reader env)
>>          {:a :a})
>>    :core (component/using
>>             (map->Foobar {:env env})
>>             {:a :a
>>
>>               :updater :updater
>>
>>              :reader :reader })))
>>
>> *fig.1 *
>>
>>
>> I was hoping to use Component to manage all internal application state.
>> But maybe it's not designed for this use case (state changes between
>> components). I imagine that immutability is preventing all those duplicates
>> from seeing the modifications. However, in this case I do need an update to
>> :a in one component, to be accessed by another component.
>>
>> Any suggestions on patterns here? I'm also looking at
>> component/update-system<https://github.com/stuartsierra/component/blob/master/src/com/stuartsierra/component.clj#L116>.
>> But again, I don't have access to the core *system* var, from within my
>> components.
>>
>>
>> Any insights appreciated
>>
>> Tim Washington
>> Interruptsoftware.com <http://interruptsoftware.com>
>>
>>
> --
> Kind Regards,
> Atamert Ölçgen
>
>
> www.muhuk.com
>
> --

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to