-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
on keeping all the reducing functions on the store module (Part II) #34
Comments
That's good! Just some other details on our conversation yesterday:
|
The more I think about this, the more comfortable I feel with this approach. When introducing new people to the team, we always insist on how the homogenous API of these observables is a big plus, and how once we "give a name" to a potentially complex (or, in this case, potentially "magical") construction, we forget about its innards and just use it as simply as we'd use a If anything, I think the higher order observable could be more idiomatically expressed as an operator; something that looks more like, const initialData$ = ajax('https://jsonplaceholder.typicode.com/posts/1').pipe(withPreloader('Loading article eins')) But I'd be curious to see how this Exercise for the reader, etc. but could be useful and cool. Tho not necessarily in that order. |
Same thing could be applied to |
Trying my hand at over-generalising this. Not sure it's a good idea, but if we want to apply it to flogs* and to modals: function withWrapper$(source$, onBefore, onAfter) {
return Observable.create(
o => {
onBefore()
source$.subscribe(o)
return onAfter
}
)
} *We all know it's just an excuse to use the |
Or even, pipable (I'm just sketching in comments, so it might not even be parse-able code): function withWrapper$ (onBefore, onAfter) {
return function (source$) {
return Observable.create(
o => {
onBefore()
source$.subscribe(o)
return onAfter
}
)
}
} |
... I mean, exporting the general method and the specialised methods we believe are useful in cv? So that anyone could create their own wrappers? |
Why not :-) I like the pipeable version. It's almost short enough as not to be needed, but only almost, not quite. Why not have it in? And, yes, we can sketch the two or three things that can use it and expose them as well. |
Because I can't clone this repo on my workstation 🤣 (I / we can start a PR later or tomorrow) |
@cristiano-belloni, man, (but spamming the friends, as well, @ollyhayes, @mamapitufo) still in the spirit of #16, and following on the conversations / complications that we were having today,
Streams that don't emit reducers but only their raw material are the most useful. We can compose them into other streams, keeping the tree of streams untangled.
But once we need to control flows, and need to orchestrate processes, we start to build up streams that emit other stuff... so we "homogenize and pausterize" by converting the raw material into reducing functions---I still feel weird calling them reducers.
Classic example: loaders: when we load data we like to show a preloader "Loading wonderful stuff... hang on", load the data, and then remove the preloader.
We normally emit a reducer for the loader, load the data, but instead of emitting it, we emit a reducer that will stow it on the state, then we emit another reducer to clear the loader.
This means we cannot really use the data raw as input to other streams.
Or we can, if we pluck it out, but then risk that the time the data was actually fetched, was not the time it was sandwhiched between preloaders.
So what if we could separate the streams: have a stream that just emits data, and a stream that just emits "preloaders", but have them synchronized through higher order observable magic?
A bit like what we've done with location: we can, and do, subscribe to the
location$
stream, not only to drive the routes, but also analytics, etc., but we can still drive it from a composing stream that interweaves actions?To go back to our loading example, what if instead of doing,
... we could do instead,
It's shorter, but most importantly, I'd emit the fffing data, so it can be plugged into other stuff.
And the knowledge of where in the store using stow on the
store$
module definition.This can be implemented quite cleanly (at least when-do-I-start-and-when-do-I-end bit) using a simplish
Observable.create
construction. For example, and very roughly,... and so on and so forth?
For loaders, we can nest them, and control all the stacking stuff on the new
loader$
as well, simplifying the view quite a lot. No need to understand preloader stacks / lasagna on thetoView
function.Because, man, remember what that other Great Italian said,
The text was updated successfully, but these errors were encountered: