Double-sent requests
See original GitHub issueFrom @staltz on July 17, 2015 9:2
function main(responses) {
console.log('This only gets called once.')
const url = '/ontologies/acl.ttl';
var request$ = Cycle.Rx.Observable.just(url);
var vtree$ = responses.http
.do(r => console.log('this gets called twice', r))
.mergeAll()
.do(r => console.log('this gets called once', r))
.map(res => h('p', res.text.substr(0, 100) + '...'));
return {
dom: vtree$,
http: request$
};
}
let [requests, responses] = Cycle.run(main, {
dom: makeDOMDriver('#app-container'),
http: makeHTTPDriver(),
db: makeLocalDbDriver(),
});
Copied from original issue: cyclejs/cycle-http-driver#9
Issue Analytics
- State:
- Created 8 years ago
- Comments:29 (22 by maintainers)
Top Results From Across the Web
HTTP requests being executed multiple times #262 - GitHub
I'm trying to build a simple login form where, in the happy path, you type your email and password, click login, a network...
Read more >How should I word this? I double-sent an order because of the post ...
I double-sent an order because of the post office. So I hope this is allowed. I sell on Etsy, 3d printed stuff ......
Read more >154484 – [patch] request for new functionality. jail zfs dataset on jail ...
No way to define zfs dataset to use it whithin jail on jail start up by /etc/rc.d/jail Fix: I've written simple patch to...
Read more >Why did the person I sent a message to get duplicate ...
Enter the phone number which the messages were sent to and press "Make Request". An XML or JSON file listing the messages sent...
Read more >The Sportula: Microgrants for Classics Students on Twitter: "1 ...
1 grantee we double-sent $; they told us and returned it. ... What gets me about so many of these requests is how...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@vladap
shareReplay(1)
is “required” for streams withscan()
otherwise they don’t broadcast a “current” state on subscribe. Usually it leads to initial state being “missed”. So my rule of thumb is to addshare()
to every stream you expose (outside function / module) and to addshareReplay(1)
to every stateful stream.The other thing with
scan()
is that such streams are moving away from event streams to data streams. For event streams timing is crucial so--1--1-->
may very well differ from--1---->
.For data streams they are kinda the same so we can discard adjacent events carrying the same data. Hence avoiding excessive recalculations bound to a state change. So you’ll probably want to
distinctUntilChanged()
streams withscan()
most of the time.I’m actually playing with a store abstraction:
Which works great with currying. You just need to feed a “store” unary functions (from state to state or
s -> s
).I apologize for spamming this thread 😥 Here is one final post.
It’s getting better. For example, they renamed
replay
topublishReplay
which is a good clarification.I’ll try to explain. Everything is quite simple once you get it 😄
RxJS has cold
Observable
and hotSubject
primitives. In short: cold is deterministic streams while hot is for non-deterministic ones. That’s a long story so I’ll just say I would prefer having Hot by default. Requirement of manualshare()
is not satisfying and error-prone.To make an
Observable
behave (like) hot RxJS fake it usingSubject
under the cover. Because this is the simplest implementation.RxJS exposes a
multicast()
operator which does what desribed in 2. But it expects an exact Subject type to work. And there is more than one…So RxJS predefines two flavors of
multicast
. Just for your convenience.If you look at the RxJS sources – those above are almost oneliners (extra code is for polymorphism and other stuff irrelevant for explanation).
There is one more step. Hot Observables need to be run manually (almost by definition). So you call
connect()
on them to start event flow.But often you want to avoid this manual book-keeping and fire a flow automatically once you have a first subscriber.
So RxJs implements a
refCount()
operator which does that for you.These are also oneliners. One for each code branch above.
To recap
Of course all above is oversimplified but I hope you’ve got the point 😉 My explanation still misses two points:
But (as I said), I’m going to write an article and I don’t have a space to cover all this here.