Skip to content
Browse files

Stop using .-strobj in clojure.browser.{dom,net} and TwitterBuzz

  • Loading branch information...
1 parent ec1a85c commit ac767433c1203ddbf278f8b8860c3debe377c2c2 @michalmarczyk michalmarczyk committed with David Nolen Apr 17, 2012
View
11 samples/twitterbuzz/src/twitterbuzz/core.cljs
@@ -195,17 +195,16 @@
(remove empty?)
(remove (:ignore-mentions @state))))
-;; TODO: replace call to .strobj with whatever we come up with for
-;; creating js objects from Clojure maps.
-
(defn fetch-mentioned-tweets
"Query twitter for usernames which are currently missing data in the
graph. Limit this query to max-missing-query names."
[missing]
(let [q (apply str (interpose " OR " (map #(str "from:" %)
(take max-missing-query missing))))]
(set-tweet-status :okay "Fetching mentioned tweets")
- (retrieve (.-strobj {"q" q "rpp" results-per-page})
+ (retrieve (doto (js-obj)
+ (aset "q" q)
+ (aset "rpp" results-per-page))
#(add-missing-callback missing %)
error-callback)))
@@ -214,7 +213,9 @@
[]
(when-let [tag (:search-tag @state)]
(set-tweet-status :okay "Fetching tweets")
- (retrieve (.-strobj {"q" tag "rpp" results-per-page})
+ (retrieve (doto (js-obj)
+ (aset "q" tag)
+ (aset "rpp" results-per-page))
new-tweets-callback
error-callback)))
View
15 samples/twitterbuzz/src/twitterbuzz/dom-helpers.cljs
@@ -41,9 +41,6 @@
[tag (merge attrs (first args)) (rest args)]
[tag attrs args])))
-;; TODO: replace call to .strobj with whatever we come up with for
-;; creating js objects from Clojure maps.
-
(defn element
"Create a dom element using a keyword for the element name and a map
for the attributes. Append all children to parent. If the first
@@ -52,12 +49,12 @@
[tag & args]
(let [[tag attrs children] (normalize-args tag args)
parent (dom/createDom (name tag)
- (.-strobj (reduce (fn [m [k v]]
- (assoc m k v))
- {}
- (map #(vector (name %1) %2)
- (keys attrs)
- (vals attrs)))))
+ (reduce (fn [o [k v]]
+ (aset o k v))
+ (js-obj)
+ (map #(vector (name %1) %2)
+ (keys attrs)
+ (vals attrs))))
[parent children] (if (string? (first children))
[(set-text (element tag attrs) (first children))
(rest children)]
View
23 src/cljs/clojure/browser/dom.cljs
@@ -7,7 +7,8 @@
;; You must not remove this notice, or any other, from this software.
(ns clojure.browser.dom
- (:require [goog.dom :as gdom]))
+ (:require [goog.dom :as gdom]
+ [goog.object :as gobject]))
(defn append [parent & children]
(apply gdom/append parent children)
@@ -41,15 +42,15 @@
([this attrs children]
(log "string (-element " this " " attrs " " children ")")
(let [str-attrs (if (and (map? attrs) (seq attrs))
- (.-strobj (reduce (fn [m [k v]]
- (log "m = " m)
- (log "k = " k)
- (log "v = " v)
- (when (or (keyword? k)
- (string? k))
- (assoc m (name k) v)))
- {}
- attrs))
+ (reduce (fn [o [k v]]
+ (log "m = " m)
+ (log "k = " k)
+ (log "v = " v)
+ (when (or (keyword? k)
+ (string? k))
+ (aset o (name k) v)))
+ (js-obj)
+ attrs)
nil)]
(log-obj str-attrs)
(if (seq children)
@@ -135,7 +136,7 @@
"Set properties on an element"
[e m]
(gdom/setProperties (ensure-element e)
- (.-strobj m)))
+ (apply gobject/create (interleave (keys m) (vals m)))))
(defn set-value
"Set the value property for an element."
View
12 src/cljs/clojure/browser/net.cljs
@@ -132,12 +132,12 @@ Includes a common API over XhrIo, CrossPageChannel, and Websockets."
(goog.net.xpc.CrossPageChannel. (gjson/parse config))))
([config]
(goog.net.xpc.CrossPageChannel.
- (.-strobj (reduce (fn [sum [k v]]
- (if-let [field (get xpc-config-fields k)]
- (assoc sum field v)
- sum))
- {}
- config)))))
+ (reduce (fn [sum [k v]]
+ (if-let [field (get xpc-config-fields k)]
+ (aset sum field v)
+ sum))
+ (js-obj)
+ config))))
;; WebSocket is not supported in the 3/23/11 release of Google
;; Closure, but will be included in the next release.

0 comments on commit ac76743

Please sign in to comment.
Something went wrong with that request. Please try again.