Giter VIP home page Giter VIP logo

Comments (2)

ibdknox avatar ibdknox commented on June 15, 2024

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.

djhworld avatar djhworld commented on June 15, 2024

Ah thanks for the prompt reply Chris and the tips on restructuring my code too!

from fetch.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.