day8 / re-frame

A ClojureScript framework for building user interfaces, leveraging React
http://day8.github.io/re-frame/
MIT License
5.44k stars 716 forks source link

Add <sub and >evt to re-frame.core #645

Closed mokr closed 4 years ago

mokr commented 4 years ago

The code I would like to see added to re-frame.core:

(def <sub (comp deref re-frame.core/subscribe))
(def >evt re-frame.core/dispatch)

These are just convenience functions, but I find myself using them all the time. The only drawback is that I always have to first add them to a utils namespace and then require that namespace virtually everywhere. It would be great to just get them from re-frame itself.

I do understand that not everyone's preferred shorthand can be added to the project, but <sub is already mentioned in the doc string of subscribe, it's short and helps avoid forgetting to deref. >evt is just as short and the natural counterpart.

If forced to come up with a con: it could maybe be confused with naming conventions seen used for core.async.

Unless I'm not mistaken the idea was introduced in this lambdaisland blog

schpaa commented 4 years ago

You know about https://github.com/deg/iron right?

mike-thompson-day8 commented 4 years ago

@mokr Yes, we describe this approach in the re-frame docs.

But I don't want to create duplicates in the official re-frame API. There should only be one way to do something. It is then up to others to add whatever further layers they want.

If I had my time over again, I would change dispatch to emit because it is shorter. But at this point stability is more important than any little tweaks like that.

Closing.