> Also, how would I set some state on the component?
When building your component, you can use :init-state to initialise the
state once (during mounting, it will not be set again unless you
unmount/remount), or :state to set the state during each render. For
example:
(om/build world-view props {:init-state {:world []}})
or
(om/build world-view props {:state {:world []}})
or both:
(om/build world-view props {:init-state {:foo 123} :state {:world []}})
The state seems to get set like this:
During initialisation: (conj (call to init-state) (value passed in with
:init-state))
During render: (conj (old value of state) (value passed in with :state))
Which means that during first render you get: (conj (call to init-state)
(value passed in with :init-state) (value passed in with :state))
Basically, the init-state function is called first, then the value passed
in with :init-state is added (and keys that already exist are overwritten)
an finally the :state passed in during render is added (again, overwriting
keys that already exist).
On 15 June 2014 12:46, Moritz Ulrich <[email protected]> wrote:
> World isn't in scope, therefore it's nil, :data is nil and (count nil) is
> zero.
> Am 15.06.2014 13:27 schrieb <[email protected]>:
>
> I have change initstate to this:
>>
>> (defn world-view [data owner opts]
>> (reify
>> om/IInitState
>> (init-state [_]
>> {:world []})
>>
>> om/IWillMount
>> (will-mount [_]
>> (go (while true
>> (log (count (:data world)))
>> (if (= (count (:data world)) 0)
>> (let [world (<! (get-world (:dimensions opts)))]
>> (om/transact! data #(assoc % :world world)))
>> (log "never gets here")
>> (<! (timeout (:poll-interval opts)))))))
>>
>> What I do not understand is why when I log the count of (:datat world) is
>> that it is always 0.
>>
>> Also, how would I set some state on the component?
>>
>> On Tuesday, June 10, 2014 2:04:30 PM UTC+1, David Nolen wrote:
>> > Your init-state method is not correct, it should return a map - using
>> >
>> > transact! there is not recommended. The tutorials/documentation cover
>> >
>> > some of these point. You could do what you want by setting some local
>> >
>> > state of the component after the first time to some other value and
>> >
>> > checking for that in your go loop.
>> >
>> >
>> >
>> > HTH,
>> >
>> > David
>> >
>> >
>> >
>> > On Sat, Jun 7, 2014 at 11:54 AM, <[email protected]> wrote:
>> >
>> > > I have the following component:
>> >
>> > >
>> >
>> > > (defn world-view [data owner opts]
>> >
>> > > (reify
>> >
>> > > om/IInitState
>> >
>> > > (init-state [_]
>> >
>> > > (om/transact! data [:world] (fn [] [])))
>> >
>> > >
>> >
>> > > om/IWillMount
>> >
>> > > (will-mount [_]
>> >
>> > > (go (while true
>> >
>> > > (let [world (<! (get-world (:dimensions opts)))]
>> >
>> > > (om/transact! data #(assoc % :world world)))
>> >
>> > > (<! (timeout (:poll-interval opts))))))
>> >
>> > >
>> >
>> > > om/IRender
>> >
>> > > (render [_]
>> >
>> > > (apply dom/table nil
>> >
>> > > (om/build-all row (:world data))))))
>> >
>> > >
>> >
>> > >
>> >
>> > > This works as expected what I want to do is to call a different
>> method after the initial get-world method has been called.
>> >
>> > >
>> >
>> > > After get-world has been called I then want to call a different
>> method that does a PUT with the data returned from get-world. The
>> setTimeOut function would then call this PUT on every time out.
>> >
>> > >
>> >
>> > > I'm not sure how to update the data after the initial get-world has
>> been called.
>> >
>> > >
>> >
>> > > --
>> >
>> > > Note that posts from new members are moderated - please be patient
>> with your first post.
>> >
>> > > ---
>> >
>> > > You received this message because you are subscribed to the Google
>> Groups "ClojureScript" group.
>> >
>> > > To unsubscribe from this group and stop receiving emails from it,
>> send an email to [email protected].
>> >
>> > > To post to this group, send email to [email protected].
>> >
>> > > Visit this group at http://groups.google.com/group/clojurescript.
>>
>> --
>> Note that posts from new members are moderated - please be patient with
>> your first post.
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "ClojureScript" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> To post to this group, send email to [email protected].
>> Visit this group at http://groups.google.com/group/clojurescript.
>>
> --
> Note that posts from new members are moderated - please be patient with
> your first post.
> ---
> You received this message because you are subscribed to the Google Groups
> "ClojureScript" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/clojurescript.
>
--
Note that posts from new members are moderated - please be patient with your
first post.
---
You received this message because you are subscribed to the Google Groups
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/clojurescript.