Comments (2)
Unfortunately that's the nature of programming in JS on the browser. Forcing an ajax request to be synchronous would actually consume the entire UI thread (you wouldn't be able to click on links, highlight text, do anything).
To do what you described you'd have to invert the way you're thinking about it. An example solution might look like this:
(defn alert-handler [r]
(js/alert r))
(defn get-results-from-server [arg handler]
(letrem [r (get-results arg)]
(handler r)))
(defn command-handler [input arg]
(condp = input
"get" (get-results-from-server arg alert-handler)))
Alternatively, instead of using condp, this looks like a perfect time to use a multi-method:
(defmulti handle-command keyword)
(defmethod handle-command :get [input arg]
(letrem [r (get-results arg)]
(js/alert r)))
I would definitely recommend the multi-method approach based on the little description you gave :)
from fetch.
Ah thanks for the prompt reply Chris and the tips on restructuring my code too!
from fetch.
Related Issues (11)
- fetch.remotes is missing (:require [cljs.reader :as reader) HOT 1
- Allow defremote to accept optional doc strings.
- remotes cannot receive (to clojure) some unicode characters in strings
- Updating dependencies make fetch work again...
- Release 0.3.0 HOT 10
- Firefox unable to call remote function HOT 2
- Optionally allow remote to use webSockets
- Security HOT 2
- ReferenceError: fetch is not defined - cljs HOT 2
- Problem with "fetch" when deploying as a war HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fetch.