derivatives icon indicating copy to clipboard operation
derivatives copied to clipboard

derivatives unavailable in `will-unmount` if the latter is placed after the former.

Open livtanong opened this issue 8 years ago • 2 comments

Affects get-ref.

If I understand the source correctly, this is because the derivatives mixin always includes unmount code. You can call the custom will-unmount before the derivatives mixin, but as a project gets more complex, it could lead to code that is difficult to reason about. Something more explicit could be worth exploring.

I have two suggestions:

  1. Split the derivatives mixin into separate mount and unmount functions/vars
  2. Include an optional will-unmount hook into the d/drv mixin that will get called before the mixin executes its own unmount.

livtanong avatar Jun 05 '17 16:06 livtanong

Can you maybe add a code snippet that illustrates the problem? :)

On Mon, Jun 5, 2017, 23:15 Levi Tan Ong [email protected] wrote:

Affects get-ref.

If I understand the source correctly, this is because the derivatives mixin always includes unmount code. You can call the custom will-unmount before the derivatives mixin, but as a project gets more complex, it could lead to code that is difficult to reason about. Something more explicit could be worth exploring.

I have two suggestions:

  1. Split the derivatives mixin into separate mount and unmount functions/vars
  2. Include an optional will-unmount hook into the d/drv mixin that will get called before the mixin executes its own unmount.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/martinklepsch/derivatives/issues/12, or mute the thread https://github.com/notifications/unsubscribe-auth/AAF82BMlgHwozS-2AXC3PRMjavKqzWNhks5sBCmogaJpZM4NwQU0 .

martinklepsch avatar Jun 06 '17 01:06 martinklepsch

Sorry for taking so long, I've been quite busy these past few days.

(defcs sample
  <
  rum/reactive
  (d/drv :app/data)
  #?(:cljs
     {:will-mount (fn [state]
                    ;; we have access to derivatives
                    state)
      :will-unmount (fn [state]
                      ;; no access to derivatives
                      state)})
  [state]
  nil)

livtanong avatar Jun 07 '17 06:06 livtanong