pure-frame

escherize 2016-06-04T06:38:09.000007Z

I posted in re-frame channel but this channel might be better.

escherize 2016-06-04T06:38:56.000008Z

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))

escherize 2016-06-04T06:40:12.000010Z

app-frame
;;=> #<Frame 2 handlers, 1 subscription | handlers (:initialize-db :set-kv) | subscriptions (:name)>

escherize 2016-06-04T06:42:08.000011Z

I figured out how to add more handlers too.

escherize 2016-06-04T06:42:22.000012Z

(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)>

escherize 2016-06-04T06:52:45.000017Z

I realized that pure-frame's re-frame.core namespace was included all over - so I stopped that.

escherize 2016-06-04T06:53:03.000018Z

now I need to simply build dispatch/subscription functions that work on the app-frame frame...

escherize 2016-06-04T06:57:56.000019Z

I think I figured out how to subscribe...

escherize 2016-06-04T06:58:00.000020Z

(re-frame.frame/subscribe app-frame [:name])

escherize 2016-06-04T07:28:40.000021Z

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!!

escherize 2016-06-04T08:32:52.000002Z

Now I have a good question:

escherize 2016-06-04T08:33:09.000003Z

It looks like my subscription handlers are only being passed the subscription vector.

escherize 2016-06-04T08:33:47.000004Z

(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)

escherize 2016-06-04T08:34:53.000005Z

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

escherize 2016-06-04T08:35:57.000006Z

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

escherize 2016-06-04T08:42:27.000012Z

Here's the repo that I've been messing with.

escherize 2016-06-04T08:42:28.000013Z

https://github.com/escherize/p-frame

escherize 2016-06-04T08:43:12.000015Z

any help around how to get the subscription functions passed the app-db atom would be πŸ’― πŸ’―πŸ‘Œ:skin-tone-3:

gadfly361 2016-06-04T09:01:59.000016Z

+1

2016-06-04T10:40:20.000021Z

also read comments in my original PR: https://github.com/Day8/re-frame/pull/107#issuecomment-131852982

escherize 2016-06-04T11:48:39.000023Z

@darwin: Thanks that's just what I needed. I missed it because (I think) I'm using the 0.5.0-style implementation.

1πŸ‘
escherize 2016-06-04T11:50:05.000024Z

@darwin: The next step in my pure-frame odessy is getting dev-cards working. Would you happen to have a reference implementation laying around? πŸ˜„

2016-06-04T11:50:57.000025Z

no, haven’t used it with dev-cards specifically