You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sharing some ideas I had in mind when writing Tape Framework; they may find their way in Re-Frame.
1. Ditch the registry (potentially)
Let's say we define handlers/subs as plain functions:
(nsmy.handlers)
(defnincrement [db _]
(update db ::count inc))
And that we use namespaced keywords exclusively for event/sub names: (rf/dispatch [:my.handlers/increment]).
The keyword has enough info to retrieve the handler from the global namespaces tree js/window.my.handlers.increment (then again, that does not work with advanced optimizations unless ^:export).
We no longer have to register in a registrar.
How about interceptors? They can be added as metadata (same for subs signals). Assumes the handler lookup will know to wire them:
(defnincrement
{::rf/interceptors [(rf/path:foo)]}
[db _]
(update db ::count inc))
2. Fn metadata
On the lines of EP 001-CaptureHandlerMetadata, if we follow the above, we can add metadata at the defn level:
(defnincrement
{::rf/kind:reg-db::rf/id::inc::rf/interceptors [(rf/path:foo)]}
[db _]
(update db ::count inc))
:doc, :ns, :line :file follow from normal defn metadata.
Using such metadata can also automate registration, by walking ns-publics of namespaces under a path, and registering in re-frame according to metadata.
3. Write symbols, use kws behind the scenes ("Ergonomic API")
Making things navigable (ie. "jump to definition") is really helpful in dealing with legacy codebases.
Subscribe/dispatch could have macro based equivalents that take the handler symbol as argument and compile to the keyword:
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Sharing some ideas I had in mind when writing Tape Framework; they may find their way in Re-Frame.
1. Ditch the registry (potentially)
Let's say we define handlers/subs as plain functions:
And that we use namespaced keywords exclusively for event/sub names:
(rf/dispatch [:my.handlers/increment])
.The keyword has enough info to retrieve the handler from the global namespaces tree
js/window.my.handlers.increment
(then again, that does not work with advanced optimizations unless ^:export).We no longer have to register in a registrar.
How about interceptors? They can be added as metadata (same for subs signals). Assumes the handler lookup will know to wire them:
2. Fn metadata
On the lines of EP 001-CaptureHandlerMetadata, if we follow the above, we can add metadata at the defn level:
:doc, :ns, :line :file follow from normal defn metadata.
Using such metadata can also automate registration, by walking ns-publics of namespaces under a path, and registering in re-frame according to metadata.
3. Write symbols, use kws behind the scenes ("Ergonomic API")
Making things navigable (ie. "jump to definition") is really helpful in dealing with legacy codebases.
Subscribe/dispatch could have macro based equivalents that take the handler symbol as argument and compile to the keyword:
(rf/dispatch+ [my.core/increment]) ; => (rf/dispatch [:my.core/inc])
Tape MVC
Some of this stuff is already present in Tape MVC if you want to have a feel for it.
Beta Was this translation helpful? Give feedback.
All reactions