Skip to content
Browse files

not impressed with rerender performance

  • Loading branch information...
1 parent cff4360 commit 71234b3e4c56c2ccf1c7a6dd655aecfc2da2064f @xadn committed
Showing with 393 additions and 4,873 deletions.
  1. +341 −4,861 om_infinite_scroll.js
  2. +52 −12 src/om_infinite_scroll/core.cljs
View
5,202 om_infinite_scroll.js
341 additions, 4,861 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
64 src/om_infinite_scroll/core.cljs
@@ -1,19 +1,59 @@
(ns om-infinite-scroll.core
(:require [om.core :as om :include-macros true]
- [sablono.core :as html :refer-macros [html]]
- [clojure.test.check.generators :as gen]
- ))
+ [om.dom :as dom :include-macros true]))
+ ; [sablono.core :as html :refer-macros [html]]
(enable-console-print!)
-
(println "hello")
-(defn widget [data]
- (om/component
- (html [:div {:className "is-panel"}
- [:ol {:className "is-content"} (for [n (range 1 1000)]
- [:li {:className "is-item"}
- [:div "Banh mi selfies shabby chic disrupt polaroid roof party. Portland High Life brunch sustainable, plaid Kickstarter pickled four loko 3 wolf moon whatever."]
- ])]])))
-(om/root widget {} {:target js/document.body})
+(defn panel-item [data]
+ (let [name "Banh mi selfies shabby chic disrupt polaroid roof party. Portland High Life brunch sustainable, plaid Kickstarter pickled four loko 3 wolf moon whatever."]
+ (dom/li #js {:className "is-item"}
+ (dom/div #js {} (:id data))
+ (dom/div #js {} name)
+ )))
+
+; DOM read + set-state
+; (defn handleScroll [owner e]
+; (let [node (om/get-node owner)]
+; (om/set-state! owner :scrollTop (.-scrollTop node))))
+
+; DOM read + set-state
+(defn handleScroll [owner e]
+ (let [node (om/get-node owner)
+ scrollTop (.-scrollTop node)
+ state (om/get-render-state owner)]
+ (if (not= scrollTop (:scrollTop node)) (om/set-state! owner :scrollTop scrollTop))
+ ))
+
+; DOM read
+; (defn handleScroll [owner e]
+; (let [node (om/get-node owner)]
+; (println (.-scrollTop node))))
+
+; Set-state only
+; (defn handleScroll [owner e]
+; (om/set-state! owner :scrollTop 1))
+
+; Nothing
+; (defn handleScroll [owner e])
+
+(defn panel [data owner]
+ (reify
+ om/IRenderState
+ (render-state [this state]
+ (. js/console (count "render"))
+ (dom/div #js {:className "is-panel" :onScroll (partial handleScroll owner)}
+ (apply dom/ol #js {:className "is-content"}
+ (map (fn [n] (panel-item {:id n})) (range 1 1000)))))
+ ))
+
+(om/root panel {:text "Hello world!"} {:target js/document.body})
+
+ ; om/IShouldUpdate
+ ; (should-update [this _ nextState]
+ ; false
+ ; )
+ ; (let [prevState (om/get-render-state owner)]
+ ; (not= (:scrollTop nextState) (:scrollTop prevState))

0 comments on commit 71234b3

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