This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-06-06
Channels
- # announcements (1)
- # beginners (147)
- # boot (9)
- # calva (28)
- # cider (3)
- # circleci (18)
- # cljdoc (54)
- # cljs-dev (55)
- # cljsrn (22)
- # clojure (179)
- # clojure-canada (9)
- # clojure-dev (74)
- # clojure-europe (1)
- # clojure-italy (15)
- # clojure-nl (7)
- # clojure-spec (30)
- # clojure-uk (55)
- # clojurescript (65)
- # core-async (15)
- # cursive (12)
- # datomic (16)
- # events (4)
- # fulcro (25)
- # graalvm (3)
- # joker (2)
- # kaocha (15)
- # keechma (94)
- # off-topic (12)
- # qlkit (2)
- # re-frame (15)
- # reagent (11)
- # reitit (29)
- # remote-jobs (15)
- # rewrite-clj (16)
- # shadow-cljs (73)
- # spacemacs (144)
- # sql (3)
- # tools-deps (11)
- # unrepl (19)
- # vim (35)
Dev workflow question : If i'm debugging a "state complex" thing like a wizard-like group of pages/panels, the state will typically be under the entity-db and kv keys. But that state is wiped out on each start-app!
... So now, each time i save a file, i need to click again in the browser to rebuild the state. Is something wrong with my setup ? I don't think it would be great to have the whole state detail encoded in the url ?
when only using the on-js-reload trick the changes to my components do not show until a hard refresh in the browser
i generally had to change most of defs from examples to defn to have a good reload behavior and fast iterations
actually saving the whole app-db thing will mess with the internals, so just save/restore the kv and entity-db parts
@carkh you can pass the :initial-data
attribute to app def when you're starting the app. This will be stored in the app-db atom when the app is started
I would do (select-keys @prev-app-db [:kv :entitydb])
You can do it in keechma too, the underlying system is the same
Both keechma and re-frame use reagent's reaction
macro
Although in keechma it's more explicit
but what woudl be the correct incantation to create a subscription that would go inside that get-kv example
when you create subscriptions you will always get app-db as the first arg
and then anything else you passed to sub> as subsequent args
ok so the dependencies would come from where i use it....like in a component (let [my-sub (sub> :my-sub previous-sub)] ...
I would do it like this:
(defn foo-sub [app-db-atom]
(reaction
(get-in @app-db-atom [:kv :foo])))
(defn bar-sub [app-db-atom]
(reaction
{:foo @(foo-sub app-db-atom)
:bar (get-in @app-db-atom [:kv :bar])}))
(def subscriptions
{:foo foo-sub
:bar bar-sub})
and keechma is caching subscriptions on the ui layer
so you don’t need to use form-2 components
when calling sub>
btw, just something interesting, not completely related - since keechma is not using any globals, you can cut-off app db on the component level and create new one that you manually update. We used this to animate page level transitions on mobile, where you don’t want to change previous page when the next page is being animated in
(defn renderers->components [components]
(reduce-kv (fn [acc k v]
(let [c-meta (meta v)
context (get c-meta :keechma.ui-component/context)]
(assoc acc k
(assoc context :components (renderers->components (:components context))))))
{} (or components {})))
(defn make-internal-ctx [ctx]
(reduce-kv
(fn [acc k v]
(let [c-meta (meta v)
renderer (get c-meta :keechma.ui-component/renderer)
context (get c-meta :keechma.ui-component/context)
components (or (:components context) {})
component-deps (vec (or (keys (:components context)) []))
comp-ctx (merge context
{:app-db (:app-db acc)
:components (renderers->components components)
:component-deps component-deps})]
(assoc-in acc [:components k] (ui/component->renderer acc comp-ctx))))
ctx (:components ctx)))
(defn replace-app-db-in-ctx [ctx app-db]
(let [current-route-fn (fn [] (reaction (:route @app-db)))]
(-> ctx
(assoc :app-db app-db)
(assoc :current-route-fn current-route-fn))))
(defn render-panel [ctx page]
(let [app-db (:app-db ctx)
rendering-page-atom (atom page)
internal-app-db (r/atom @app-db)
internal-ctx (make-internal-ctx (replace-app-db-in-ctx ctx internal-app-db))
watch-id (gensym :transition-watch)]
(add-watch app-db watch-id
(fn [key ref _ new-val]
(let [current-page (:key (get-in new-val [:route :data]))
rendering-page @rendering-page-atom]
(when (or (nil? rendering-page)
(= current-page rendering-page))
(reset! internal-app-db new-val)))))
(r/create-class
{:reagent-render (fn [_ page]
(reset! rendering-page-atom page)
(when page
[(ui/component internal-ctx page)]))
:component-will-unmount (fn []
(remove-watch app-db watch-id))})))
this basically rewrites the deps (both the components and subscriptions), so they all use new app-db
nice, this looks very useful, I could steal it for our projects 😄
anyways you could just replace that eql/middleware by a graphql/middleware and there you go protocol change in a single line of code
yeah, this makes sense
yeah, which is why they are not really used in Keechma, although I would say that pipelines can act in a similar fashion (as a series of steps that get executed)
i don't know if that woudl make sense to accept promise return values from the loader functions
yeah - no controller context
although I did experiment with pipelines in server-side context - where I had more general implementation
maybe it would make sense to make a general pipeline lib
i don't know that it would make sense to abstract more, then you're back at general monadic stuff and there are libraries for that already
in my app i open a file, so this opens the file dialog, and html only will warn me when the user press ok
They sit there waiting, alone :). I guess that since they are blocked in go-loop, the state stays in memory which could mean it's a slow memory leak
I think you should not do anythign about this promise thing. If i return a promise, the contract is that I will either resolve or reject it. If I break that contract, that's a "me" problem, not a keechma problem
If the controller is stopped, I think they should be cleaned up
Hm, this is an interesting one, since the promise is not resolved, it will actually never come to the release step
Exclusive will mark the pipeline as done, but pipeline itself must get to the point where it checks if it should proceed
If it just waits, then it will never happen
Yeah, it's probably not a huge deal, but an interesting problem
Yeah, I'll think about adding this internally
But now I'm aware of the problem so it's a problem for me :)