Open mistyharsh opened 5 years ago
@mistyharsh I like the idea, especially with the idea of pipeline operator compatibility. I would really like to see this proposal soon 😋
Currently I'm building the similar response creator inside new websockets
package and right now our ideas are very similar. Regarding your concept, I was thinking about dedicated rx-operator which will expose some builder as a second argument. Why an operator? Because it is more explicit.
const effect$ = req$ =>
req$.pipe(
// ...
mapToResponse((input, b) => b.status(200).pipe(
b.status(400),
b.body(input),
b.header('key', 'value', options)
// ...
)
),
);
In the above example, the mapToResponse
will deliver a piped input
value from previous operator and builder/creator/factory/whaeva
which then can be used for building an EffectResponse
object.
BTW. I would really love to see this kind of operator in @marblejs/core
package! 💪
Thank you @JozefFlakus for the inputs. The idea of having a dedicated builder interface is a great. I will experiment with this and see where it leads us.
Hi all,
Currently, we are in a process of building a response helpers/toolkit for Marble.js. Effect object expects
{ status?, body?, headers? }: EffectResponse
as the standard object. However, it is often clumsy to work with headers when headers likeContent-Type
,Location
orCookie
are involved.Thus, we are building a fluent-like yet functional interface to simply generating
EffectResponse
object. I have basically two things in mind:In the above example every function has uniform return type:
Observable<EffectResponse>
. Every fuction likecode
,body
, etc. is basically a customRx.js
operator. Every operator takes existing incoming response object, creates new copy after making changes and returns newEffectResponse
. There are few more functions likecreated
,location
,type
, etc. However, the problem with this syntax is cookies. Cookies are bit difficult to process as I might need to parse existingSet-Cookie
header in this pipeline. In essence, these functions are simply manipulatingEffectResponse
and producing newEffectResponse
.Second option is maintaining a custom response object. Instead of manipulating
EffectResponse
, they will manipulate a custom internal object. One the user is done with the pipeline, he will have to invokebuild()
function which will produceObservable<EffectResponse>
. Here, all the computation is differed till the lastbuild()
function. It will help enable do certain optimizations especially if cookies are encrypted and involves time consuming operations. In will look like:In above step, mr.build(x) finally produces
Observable<EffectResposne>
. Few design decisions we have made here like:Keeping it compatible with pipeline so that in future we can have much simpler interface:
@JozefFlakus @sagar735 @Krantisinh @minitesh any opinions with the syntax?