What is the advantage of core.async in clojurescript? -
Everyone is talking about the great core. What is ASINC, and how to handle event handling in closerscript makes. I'm following the tutorial, and I do not get any clear advantage from these code examples.
(defn [el type] (let [out] (chain)] (events / listen el type (fn [e] (put! E))))) () "search 1 ")" click ") (Go (while correct (dosomethingasync (& lt;! Clicks))))
versus
(
Good question!
I think your first step will be to understand the benefit
and my Below Try:
I think that if we change our code slightly then the difference will be clear.
First of all, try to highlight the sentence "all There is a time in good programs when components or subsystems stop contacting each other directly. "I think we can separate the input event channel from let fn:
(def click (dome / getElement" Search1 ")" click ")) (go true (with dosomethingasync
, with core.async, we can write asynchronous calls, such as" Can be written from different parts "We will write synchronous call (sequential code). An example of this situation requires more than one channel (Click "dom") (press (go / getElement "search1") "click") (by pressing the def key (listen (dom / getElement "search")) (from DEF -Out (Chain) (Go (While True (Let [click-get (& lt ;! Click here) (dosomethingasync click-recieved (Click! Out-out "click received!") (Let [other-input-wait (& lt ;; key-pressed]] (dosomethingwithkey other input-waiting Finally, I think that you do not use the meaning of the callback function properly. are doing. When we talk about a callback function, I think that we are discussing a function that in addition to its own parameters, it receives a function "callback". At the end of the execution of the function, we call the callback function Call to return the execution flow at the point. Changing your "callback" function came up as the following:
(defn dosomethingcallback [and call back-fn] (js / console.log "callback:" e) (call back-fn ))
And if we try to release something similar to the same code obtained from the previous code core. Syync Example:
(defn do-key [call-back-FN E] (.log JS / console "before callback key") (call-back-FN E)) Before [call-back-FN E] (.log js / console "click") (call-back-FN E) (key-callback-FN [E] (.log JS / console ("The key Is doing some work with: ")) (click-callback-fn defn [E] (.log JS / console (" This is doing some work with the click ") (Event / Listen (Get Dome / Get it! Element "search2") "keypress" (partial tax-key key-callback-FN)) (event Click "Click" (Partial Click-click-Callback-FN) (Doom / Toilet "Search2"))
Comments
Post a Comment