Get last emitted value after subscription
const RxEmitter = require('rxemitter').RxEmitter;
RxEmitter.emit("ADD_AN_NUMBER", 1);
RxEmitter.emit("ADD_AN_NUMBER", 2);
RxEmitter.on('ADD_AN_NUMBER').subscribe(x=> console.log(x));
Prints nothing. Is possible to get last value after subscription? So expected behavior is printing 2.
Forked unlight/RxEmitter
The order of registration. Your advice is good, I have to think about how to achieve. thank you very much
What is the status/resolution?
What is the status/resolution?
Sorry, I haven’t come and implemented the logic here. I'm really busy lately, sorry
To manage this behavior you should replace Subject with BehaviorSubject:
if (!this.cache[eventName].subject) { this.cache[eventName].subject = new BehaviorSubject(null); }
I think this is the only possible solution :)
@Hezard
Yes, and additionally we need add .skip(1) in on() method if subject already exists.
See my forked branch https://github.com/unlight/RxEmitter