raimohanska/bacon.js — pull request #47 by thenikso (2013-01-21 17:18:48+00:00)
Title: Replay Bus

I have a situation where I do something like this:

```javascript
var bus = new Bacon.Bus;
var property = bus.toProperty('FIRST');
bus.push('SECOND');
property.onValue(function(val) {
console.log(val);
});
```

I'd like the console to log 'SECOND' but it logs 'FIRST' instead; because (correctly) an observable does not push anything until there are no subscribers.

Inspired by [ReactiveCocoa](https://github.com/github/ReactiveCocoa) (which I suggest to look at also for other inspirations), I'd use `-replayLast` which basically subscribe to the stream for you and pushes on a 'replay subject' (read 'replay bus') with a replay count of 1.

A replay bus would replay N received values to every new subscriber before starting to forward (broadcast) the other values. In this purposed implementation, I added a few line of codes to `Bacon.Bus` that now accept a *replayCount* parameter.

If there is a different way to do that let me know :sparkles: