Skip to content

Commit

Permalink
wrap more lifecycle methods to support app-db binding
Browse files Browse the repository at this point in the history
  • Loading branch information
ul committed Mar 21, 2016
1 parent 77249b0 commit 6dfca12
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/ampere/om.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@
[c v]
@(or (om/get-state c [::rx (get-key v)]) (sub c v)))

(defn lifecycle-bind-app-db [f]
(fn [& args]
(this-as this
(binding [app-db (or (om/get-state this ::db) app-db)]
(.apply f this (into-array args))))))

(defn wrap-lifecycle [methods k]
(update methods k lifecycle-bind-app-db))

(defn wrap-lifecycles [methods ks]
(reduce wrap-lifecycle methods ks))

;; FIXME add app-db binding for all lifecycle methods
(def descriptor
(om/specify-state-methods!
Expand All @@ -57,12 +69,10 @@
(doseq [rx (vals (om/get-state this ::rx))]
(unsub* this rx))
(.call f this)))))
(update :render
(fn [f]
(fn []
(this-as this
(binding [app-db (or (om/get-state this ::db) app-db)]
(.call f this))))))))))
(wrap-lifecycles [:shouldComponentUpdate
:componentWillMount :componentDidMount
:componentWillUpdate :componentDidUpdate
:componentWillReceiveProps :render])))))

(def mergeable? (some-fn nil? map?))

Expand Down

0 comments on commit 6dfca12

Please sign in to comment.