Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

sample.js 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { OuterSubscriber } from '../OuterSubscriber';
  2. import { subscribeToResult } from '../util/subscribeToResult';
  3. export function sample(notifier) {
  4. return (source) => source.lift(new SampleOperator(notifier));
  5. }
  6. class SampleOperator {
  7. constructor(notifier) {
  8. this.notifier = notifier;
  9. }
  10. call(subscriber, source) {
  11. const sampleSubscriber = new SampleSubscriber(subscriber);
  12. const subscription = source.subscribe(sampleSubscriber);
  13. subscription.add(subscribeToResult(sampleSubscriber, this.notifier));
  14. return subscription;
  15. }
  16. }
  17. class SampleSubscriber extends OuterSubscriber {
  18. constructor() {
  19. super(...arguments);
  20. this.hasValue = false;
  21. }
  22. _next(value) {
  23. this.value = value;
  24. this.hasValue = true;
  25. }
  26. notifyNext(outerValue, innerValue, outerIndex, innerIndex, innerSub) {
  27. this.emitValue();
  28. }
  29. notifyComplete() {
  30. this.emitValue();
  31. }
  32. emitValue() {
  33. if (this.hasValue) {
  34. this.hasValue = false;
  35. this.destination.next(this.value);
  36. }
  37. }
  38. }
  39. //# sourceMappingURL=sample.js.map