Skip to content

Instantly share code, notes, and snippets.

@moea
Created November 16, 2015 19:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save moea/63d7a882e4ad333f3b5a to your computer and use it in GitHub Desktop.
Save moea/63d7a882e4ad333f3b5a to your computer and use it in GitHub Desktop.
Get, e.g. cljs-http or any goog.net.XmlHttp-based client working on Node
(ns ...
(:import [goog.net XmlHttp XmlHttpFactory])
(:require [cljs.nodejs :as nodejs]))
(def xml-http-request
(-> (nodejs/require "xmlhttprequest")
(.. -XMLHttpRequest)))
(defn NodeXhrFactory []
(this-as this (.call XmlHttpFactory this)))
(goog/inherits NodeXhrFactory XmlHttpFactory)
(set!
(.. NodeXhrFactory -prototype -createInstance)
#(xml-http-request.))
(set!
(.. NodeXhrFactory -prototype -internalGetOptions)
(constantly #js {}))
(defn set-global-xhr-factory! []
(.setGlobalFactory XmlHttp (NodeXhrFactory.)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment