-
Notifications
You must be signed in to change notification settings - Fork 126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pass "old state" to will-update
and did-update
hooks
#26
Comments
Why should state change if forceUpdate was called? What changes are you On Fri, Apr 10, 2015 at 6:57 PM Myron Mavko [email protected]
|
Consider you have a mixin ;; NOT USABLE - CONCEPT CODE
(def ^:dynamic *flagged* false)
(def mixin1
{:will-mount (fn [state]
(assoc state :flag *flagged*))
:did-mount (fn [{cmp :rum/react-component :as state}]
(go
(<! (timeout 1000))
(set! *flagged* true)
(rum/request-render cmp)))
:will-update (fn [old-state state]
(assoc state :flag *flagged*))})
(def mixin2
{:will-update (fn [old-state state]
(if (and (not (:flag old-state)) (:flag state))
(println "at last!")))})
(defc C < mixin1 mixin2 [:div "a component"]) In order to handle this case component state should be recreated (through |
Ok, I still don’t understand neither the problem nor the solution. |
Because Ok, probably the issue can be suspended till more obvious practical application found :) |
It won’t. But state won’t change as well? |
|
Right. Thanks for the explanation. I see it now (probably :) ) Rum definitely need simplification of state model. It’s too hard to walk all these possible state transitions in a head. Your problem cannot be easily fixed, because Rum has no notion of old-state. As component goes through many mixins, there’s miriad of intermediate states and they always might be considered “old” or “new” at some point. I will see what I can do about it |
I can weigh in on another example here: When I tried to port the The way I worked around it was to write a mixin for (defn cursor-to-end [local-key trigger-edit-key editref]
{:did-update
(fn [state]
(when (get @(get state local-key) trigger-edit-key)
(let [node (rum/ref-node state editref)]
(.focus node)
(.setSelectionRange node (.-length (.-value node)) (.-length (.-value node)))
(swap! (get state local-key) dissoc trigger-edit-key)))
state)})
(rum/defcs todo-item
< (rum/local {:edit-text ""} ::local) (cursor-to-end ::local :start-edit "editField")
... ) And inside the component have an on-click that sets the A bit painful to figure out, but not unworkable. |
I can compare old and new state in
transfer-state
hook, but it's not called onforceUpdate
(and that's what's done inrum/request-render
called byrum/local
mixin among other possible cases).Here's jsFiddle showing how
componentWillReceiveProps
works: http://jsfiddle.net/kb3gN/10756/The text was updated successfully, but these errors were encountered: