Permalink
Browse files

New bind data transfer options

  • Loading branch information...
1 parent f133e46 commit d592ef68d1cfa9d68f66f7cd0b8bdfa857981928 @zk committed Mar 11, 2013
Showing with 24 additions and 0 deletions.
  1. +24 −0 src/cljs/nsfw/bind.cljs
View
@@ -53,7 +53,31 @@
(when-not (= old new)
(f id old new)))))
+(defn server-push-when [!a opts should-push?]
+ (bind
+ !a
+ (fn [id old new]
+ (when (should-push? old new)
+ (ajax (merge {:path "/"
+ :method "PATCH"
+ :success #()
+ :error #()
+ :data (pr-str new)}
+ opts))))))
+
+(defn server-push [!a opts]
+ (server-push-when !a opts (constantly true)))
+
+(defn server-keys [!a opts & keys]
+ (server-push-when
+ !a opts
+ (fn [old new]
+ (not= (select-keys old keys)
+ (select-keys new keys)))))
+
(defn server [!a opts & keys]
+ ;; Track state of last server response to prevent shipping the same
+ ;; thing twice
(let [last-projection (atom (select-keys @!a keys))]
(bind
!a

0 comments on commit d592ef6

Please sign in to comment.