Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

sampleTime.js 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { Subscriber } from '../Subscriber';
  2. import { async } from '../scheduler/async';
  3. export function sampleTime(period, scheduler = async) {
  4. return (source) => source.lift(new SampleTimeOperator(period, scheduler));
  5. }
  6. class SampleTimeOperator {
  7. constructor(period, scheduler) {
  8. this.period = period;
  9. this.scheduler = scheduler;
  10. }
  11. call(subscriber, source) {
  12. return source.subscribe(new SampleTimeSubscriber(subscriber, this.period, this.scheduler));
  13. }
  14. }
  15. class SampleTimeSubscriber extends Subscriber {
  16. constructor(destination, period, scheduler) {
  17. super(destination);
  18. this.period = period;
  19. this.scheduler = scheduler;
  20. this.hasValue = false;
  21. this.add(scheduler.schedule(dispatchNotification, period, { subscriber: this, period }));
  22. }
  23. _next(value) {
  24. this.lastValue = value;
  25. this.hasValue = true;
  26. }
  27. notifyNext() {
  28. if (this.hasValue) {
  29. this.hasValue = false;
  30. this.destination.next(this.lastValue);
  31. }
  32. }
  33. }
  34. function dispatchNotification(state) {
  35. let { subscriber, period } = state;
  36. subscriber.notifyNext();
  37. this.schedule(state, period);
  38. }
  39. //# sourceMappingURL=sampleTime.js.map