This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-02-04
Channels
- # arachne (2)
- # bangalore-clj (3)
- # beginners (34)
- # boot (22)
- # cider (1)
- # cljs-dev (86)
- # cljsjs (3)
- # clojure (42)
- # clojure-argentina (6)
- # clojure-austin (10)
- # clojure-chicago (1)
- # clojure-france (3)
- # clojure-russia (135)
- # clojure-spain (1)
- # clojure-uk (4)
- # clojurescript (69)
- # core-async (13)
- # cursive (11)
- # datascript (6)
- # datomic (8)
- # dirac (2)
- # emacs (10)
- # euroclojure (1)
- # events (1)
- # gsoc (13)
- # jobs-rus (9)
- # lumo (7)
- # off-topic (18)
- # om (16)
- # perun (3)
- # planck (1)
- # portland-or (1)
- # re-frame (25)
- # ring (22)
- # spacemacs (1)
- # untangled (14)
Hi reframers, is there any way to add a global interceptor without having to rewrite all my event handlers? I'd like to write something like this:
(reg-global-interceptor
(fn [new-db old-db event]
(if (and (not= old-db new-db) (not= event :x))
(with-messages new-db)
new-db)))
@lsenta
You probably want to override re-frame's reg-event-db
and change the :require
statement in all your event files.
@lsenta Check this out https://github.com/Day8/re-frame/wiki/Alternative-dispatch,-routing-&-handling#a-see-all-handler
Arch advice please 🙂 I’m prototyping a game that uses realtime checks (i.e. music thing, people need to tap to learn to keep time). Totally ignoring JS timing issues for now, I’m wondering how best to interface this with re-frame. It feels like I should have a game loop running every frame that has nothing to do with re-frame, then dispatch events from that that affect the UI + game state. I initially thought about updating the store every frame with the current time but that seems to go against the idea of an event driven approach.
@heeton I'm actually trying to design a game based on an event driven arch too, so far I'm having my game loop syncronized to the app-db (reading directly for rendering)
@heeton No I'm using PIXI.js to render on a WebGL canvas with js' requestAnimationFrame calling my game loop
mainly game state, all game events (e.g. user input, object collision) goes through re-frame
my "game" is still early in the archetectual design phase tho, I'm just testing out pieces of code here and here.
@lsenta I use this in some debug code that I only load in development to add a debug-interceptor to all the event handlers:
(swap! re-frame.registrar/kind->id->handler
(fn [kih]
(update kih :event
(fn [ih]
(zipmap (keys ih)
(map (fn [ics]
(let [[cofx do-fx & xs] ics]
(assert (= (:id do-fx) :do-fx)
"debug makes assumption of re-frame standard interceptor order")
;; do-fx halts the interceptor chain, so insert after that one
(seq
(into [cofx
do-fx
debug-interceptor]
xs))))
(vals ih)))))))
Ho wow, thanks @mac, I haven't thought of doing it this way, and thanks @thegeez: I'd avoid digging into the internals, but if you already made it works, that'll be perfect for my hackish prototype 🙂
@qqq sure, I remember seeing a wiki page on this.... but can't seem to find it. you just need to provide a custom fx, cofx and sub to datascript.
it's surprising it's not used more; datascript seems like a great idea, and I'm surprised none of the FRP (reagent, re-frame, OM), seems to heavily use it