I posted in re-frame channel but this channel might be better.
has anyone successfully setup pure-frame?
I would like to get devcards working with re-frame
I guess I havn't found the docs ( https://github.com/binaryage/pure-frame ) super helpful (edited)
So far I have setup a Frame
with some handlers and subscriptions
[4:34] Star this message
(def frame-handlers
{:initialize-db
(fn [_ _] db/default-db)
:set-kv
(fn [db [_ k v]] (assoc db k v))})
(def frame-subs
{:name (fn [db]
(reaction (:name @db)))})
(def app-frame (pure-frame/make-frame frame-handlers frame-subs))
app-frame
;;=> #<Frame 2 handlers, 1 subscription | handlers (:initialize-db :set-kv) | subscriptions (:name)>
I figured out how to add more handlers too.
(re-frame/register-event-handler db/app-frame :event-id identity)
;;=> #<Frame 3 handlers, 1 subscription | handlers (:initialize-db :set-kv :event-id) | subscriptions (:name)>
I realized that pure-frame's re-frame.core namespace was included all over - so I stopped that.
now I need to simply build dispatch/subscription functions that work on the app-frame frame...
I think I figured out how to subscribe...
(re-frame.frame/subscribe app-frame [:name])
Ahh, the info I was looking for is actually in https://github.com/binaryage/pure-frame/blob/master/test/re_frame/test/frame.cljs I had skimmed it earlier and missed the important bits!!
Now I have a good question:
It looks like my subscription handlers are only being passed the subscription vector.
(ns p-frame.db
(:require-macros [reagent.ratom :refer [reaction]])
(:require [reagent.core :as r]
[re-frame.frame :as frame]
[re-frame.router :as router]
[p-frame.handlers :refer [handlers]]))
(def default-db {:name "re-frame"})
(def app-db (r/atom default-db))
(def subscriptions
{:name (fn [& xs] (reaction xs))})
(def ^:private app-frame (frame/make-frame handlers subscriptions))
(defonce ^:private event-queue (router/make-event-queue app-frame app-db))
(def dispatch (partial router/dispatch event-queue app-frame))
(def subscribe (partial frame/subscribe app-frame))
@(subscribe [:name])
;;=> (:name)
Here I register a subscription function that wraps everything it's given in a reaction and returns it, under the key :name
. I'm wondering what the best way to allow access to app-db
for the subscription
Here in the tests, app-db (which is a number)... is simply referenced from inside the subscribe fn: https://github.com/binaryage/pure-frame/blob/master/test/re_frame/test/frame.cljs#L129
Here's the repo that I've been messing with.
any help around how to get the subscription functions passed the app-db atom would be π― π―π:skin-tone-3:
+1
key thing: https://github.com/escherize/p-frame/blob/master/src/cljs/p_frame/db.cljs#L13
@escherize: have you seen this? https://github.com/binaryage/pure-frame/blob/master/src/re_frame/v041_api.cljs#L29-L35
also read comments in my original PR: https://github.com/Day8/re-frame/pull/107#issuecomment-131852982
@darwin: Thanks that's just what I needed. I missed it because (I think) I'm using the 0.5.0-style implementation.
@darwin: The next step in my pure-frame odessy is getting dev-cards working. Would you happen to have a reference implementation laying around? π
no, havenβt used it with dev-cards specifically