Skip to content

Instantly share code, notes, and snippets.

@coldnew
Forked from moea/http-shim.cljs
Created November 17, 2016 05:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coldnew/3ddb961a8f2aac73d75886d0b87e3f8b to your computer and use it in GitHub Desktop.
Save coldnew/3ddb961a8f2aac73d75886d0b87e3f8b 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