Skip to content
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

events & subs as defn #636

Closed
niquola opened this issue Jul 14, 2020 · 3 comments
Closed

events & subs as defn #636

niquola opened this issue Jul 14, 2020 · 3 comments

Comments

@niquola
Copy link

niquola commented Jul 14, 2020

Hello, we are happy re-frame users for many years.

We are running tests on event handlers, subs, and pure components in jvm.
This is some reflection - you may throw away if not relevant.
Recently we started using macros on top of rf/reg-sub rf/reg-event-fx to define subs and event handlers as vars
to track deps explicitly and write a little bit less code.

(defs some-subs [db params]
    (get-in db ....))

(defx some-event [{db :db} params]
     {:fx ..., :db: ...})

(defview myview [some-sub]
    [:div {:on-click #(rf/dispatch [some-ev {..}])
         (pr-str some-sub)])

Here is an idea. Because event-handlers and subscriptions are pure cljc functions
why not define and dispatch them as functions (or vars with meta) in re-frame.
Without any special registry.

(defn some-event {:cofx {:some-key [:some-fx params}, :rf/path [:path :in :db]}
    [{sk :some-key db :db} params]
    {:fx ..., :db....})

(defn some-subs [db params] ....)

(defn some-comp []
  [:div {:on-click (rf/dispatch #'some-ev params)}
      @(rf/subscribe #'some-subs params)])

73's niquola

@niquola niquola changed the title events & subs as clojure functions events & subs as defn Jul 14, 2020
@mike-thompson-day8
Copy link
Contributor

@niquola
I take your point that this approach is certainly possible. But I'm very comfortable using keywords for identities. After all, that's the reason they are in the language.

@niquola
Copy link
Author

niquola commented Jul 16, 2020

Thx @mike-thompson-day8
Just to argue: you do not use multi-methods everywhere in clojure code - you are using namespaces and functions :)

@mike-thompson-day8
Copy link
Contributor

Yeah, I do understand what you are saying, but when it comes to these kinds of decisions, the boat has sailed years ago. A disruptive change would have to bring a massive upside.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants