On Saturday, April 4, 2015 at 9:38:11 PM UTC+3, whodidthis wrote: 
> Yes you will lose everything if you change input value through dispatch as it 
> is asynchronous. Something synchronous like a local atom will work though. As 
> does re-frames app-db.
> 
> Basically you need something like 'dispatch-sync' 
> (https://github.com/Day8/re-frame/blob/master/src/re_frame/router.cljs#L54) 
> except dispatching resets entire app-db so that wont work for reasons 
> mentioned in the other thread. You need to swap app-db on your own.
> 
> (register-sub
>   ::my-secret
>   (fn [db _]
>     (reaction (::my-secret @db))))
> 
> (defn synced-change
>   [value]
>   (swap! re-frame.db/app-db assoc ::my-secret value))
> 
> (defn tags-show
>   []
>   (let [value (subscribe [::my-secret])]
>     (fn []
>       [:input {:value @value :on-change (fn [e] (synced-change (-> e .-target 
> .-value)))}])))
> 
> Maybe in the future re-frame will have a scoped dispatch-sync or whatever.

Okay, ignore this advice. Dispatch-sync instead of dispatch will work just fine 
for controlled inputs. 

I misunderstood some warnings on the other thread, sorry everyone

-- 
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.

Reply via email to