This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-12-09
Channels
- # adventofcode (187)
- # aws (1)
- # aws-lambda (1)
- # beginners (162)
- # boot (64)
- # cljs-dev (6)
- # cljsjs (2)
- # cljsrn (32)
- # clojure (357)
- # clojure-greece (1)
- # clojure-korea (4)
- # clojure-russia (63)
- # clojure-sanfrancisco (3)
- # clojure-spec (91)
- # clojure-uk (63)
- # clojurescript (74)
- # clojurex (10)
- # code-reviews (55)
- # core-async (4)
- # core-typed (1)
- # cursive (17)
- # datascript (36)
- # datomic (43)
- # devcards (4)
- # dirac (3)
- # emacs (59)
- # hoplon (286)
- # jobs-discuss (399)
- # luminus (4)
- # mount (9)
- # off-topic (30)
- # onyx (53)
- # protorepl (3)
- # re-frame (88)
- # reagent (4)
- # spacemacs (1)
- # specter (14)
- # untangled (1)
- # vim (42)
Hi, I am reading the doc of interceptors
and have a question: I am using the re-frame-template, default-db
is defined in db.cljs
. If I want to use reg-event-fx
, should I define default-db
to be the structure of context
, which has the keys :coeffects
, :effects
, :queue
, :stack
? Or should I just use the default-db
as the :db
in :coeffects
, while the context structure has already been pre-defined by re-frame
? Thanks.
some refs
{:coeffects {:event [:some-id :some-param]
:db <original contents of app-db>} ;; <== is this :db just the default-db?
:effects {:db <new value for app-db>
:dispatch [:an-event-id :param1]}
:queue <a collection of further interceptors>
:stack <a collection of interceptors already walked>} ;; <== or should I define the whole structure to be default-db?
(def-event-fx
:initialise
(fn [cofx v]
{:db default-db}))
An -fx
event handler returns a map, which represents the effects
it wishes to be made.
effects
are returned in a map.
Each key of the map identifies the effect. The value represents "further values"The :db
effect is how you say "please change the application state (app-db) to this value"
So just to be clear:
- the parameter cofx
is the :coeffects
out of the context
- the returned map will become the :effects
in the context
The above is exactly the same as this -db
version:
(reg-event-db
:initialise
(fn [db v]
default-db))
In the case of -db
handler, the only coeffect supplied (1st parameter) is the current application state. And the only effect returned is the new application state.
Gotta go
@mikethompson Thanks. Sorry for my English, not clearly understood the docs. So is there an overall context
that contains :coeffects
and :effects
which defined by re-frame? Or should I define it myself?
a context is what is passed along the interceptor chain. re-frame provides it
So the thing being passed to reg-event-db
as db , and to reg-event-fx
as cofx is not the same, right?
Best I can do here is to encourage you to read over the docs again
cofx contains :db
-db
handlers are a simple way of doing the same thing as -fx
, at the cost of being more limited
Ok. Thanks for your help. I'll treat the docs as my textbook and read it till clearly understand. It's lucky to be a student of you.
a-la-the todomvc example https://github.com/Day8/re-frame/blob/master/examples/todomvc/src/todomvc/views.cljs#L7-L23
@samueldev probably. re-com does it a similar way
thanks @mikethompson - and refresh my memory, do you know the name of the library that automatically handled dispatching things for REST requests?
Are you thinking of this: https://github.com/Day8/re-frame-http-fx
can I ask you things about that lib @mikethompson or is that best saved for @danielcompton ?
Daniel is probably better to answer, although his weekend just started
where are these ::
?
Oh, in the docs?
Right. No particular reason for the ::
. Ignore if it does not suit you.
@samueldev
those are ns-qualified keywords.
if you have a big app with multiple modules (say, foo
and bar
) and each needs a sub called name
or something generic like that.
writting ::name
in foo
will result in a sub-id of :foo/name
so it won't clash with the ::name
inside bar
awesome job @andre
@andre
very nice! but shouldn't there be a view
function that generates hiccup between subs
and Reagent
?
@akiroz there is no view function, reagent wathes the deref of ratom wich subscribtion returns
looking on the diagramm i have two questions about subscriptions, all subs will be running on app-db changes. so is it better to unsubscribe ? and what if run subs only if some value changed in the db?
@andre I love what you have done. But it scares me too. Diagrams always worry me. They invariably make something look hugely complex. Intimidating. I've got a feeling that dominos 1 2 and 3 should be on the one Diagram and 4 5 6 should be on another
yes, i'm scared too š so i'm thinking to create some interactive diagrams from simple to complex
Yeah, the hard thing to communicate in a static diagram is the passage of time
Regarding your subscription questions ...
.... I'll explain it this way ...
1. At run time there is a signal graph
2. At the root of the signal graph is app-db
3. At the leaves are views
4. In between are nodes created by reg-sub
The in-between nodes only exist because a view does a subscribe
That's a key point
reg-sub
just says that a node might exist
And if it is requested then "here's how to do it"
But no signal graph exists (is instantiated) until a subcsribe in a view happens
so , on my chart , there shouln't be an arrow from db to sub-key3 , because i don't have subscribtion in views
Exactly
Unless a view has done the necessary subscribe
, that part of the graph does not exist
So the CREATION of the signal graph is driven from the leaves of the graph (the views)
However, the later data propogation thought the graph originates from app-db
The view is itself actually a reaction :-)
So when it gets destroyed its its component-did-unmount runs around all the direct nodes in the signal graph and say "I don't need you any more"
Those nodes in turn tell their upstream nodes etc
When anyone of those nodes get to having 0 upstream nodes, they dispose of themselves
And the whole tree unwinds
Ahh, that's the trick :-)
From a design point of view, the part of re-frame I'm most pleased with is the subscriptions side of things.
You can be quite ignorant and it all just works
That's a good thing
It's weekend for me now, will look at this next week. I'm usually pretty responsive on GitHub issues, so no extra pings needed :)