Giter VIP home page Giter VIP logo

Comments (3)

mike-thompson-day8 avatar mike-thompson-day8 commented on July 17, 2024

There's nothing wrong with the idea, but I won't implement it. Closing.

Why?

  • it is generally better if there is only one way of doing things (Eg. I regret putting the syntax sugar for subscriptions into re-frame core)
  • there's already a couple of ways you can implement this choice yourself already (in not much more than 10 lines of code):
    • write and use an interceptor
    • write and use your own version of reg-event-fx

from re-frame.

mike-thompson-day8 avatar mike-thompson-day8 commented on July 17, 2024

BTW, here's what I mean by an interceptor that does the job (untested):

(def wrap-effects
  (re-frame.core/->interceptor
   :id    :wrap-effects
   :after (fn [context]
            (assoc context :effects {:fx (:effects context)}))))    ;; <-- wrap existing effects in a map like this {:fx  <existing>}

Then, write your own version of reg-effects-fx to install this wrap-effects interceptor immediately before the event handler is called (my code below is based on existing code for reg-effects-fx here)

(defn reg-event-fx2       ;; <-- my new name
  ([id handler]
   (reg-event-fx id nil handler))
  ([id interceptors handler]                                                                          ;; vvvvvvvvvvvvv
   (events/register id [cofx/inject-db fx/do-fx std-interceptors/inject-global-interceptors interceptors wrap-effects (fx-handler->interceptor handler)])))
                                                                                                      ;; ^^^^^^^^^^^^^

(also untested)

Notice the use/placement of wrap-effects

from re-frame.

sirmspencer avatar sirmspencer commented on July 17, 2024

That's neat, I will try that.

"I regret putting the syntax sugar for subscriptions into re-frame core". I just saw that expansion of syntactic sugar in 1.3 and thought this idea was in line with that. It's interesting to hear you already regret that change.

from re-frame.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.