sample.js 820 B

1234567891011121314151617181920212223
  1. import { innerFrom } from '../observable/innerFrom';
  2. import { operate } from '../util/lift';
  3. import { noop } from '../util/noop';
  4. import { createOperatorSubscriber } from './OperatorSubscriber';
  5. export function sample(notifier) {
  6. return operate((source, subscriber) => {
  7. let hasValue = false;
  8. let lastValue = null;
  9. source.subscribe(createOperatorSubscriber(subscriber, (value) => {
  10. hasValue = true;
  11. lastValue = value;
  12. }));
  13. innerFrom(notifier).subscribe(createOperatorSubscriber(subscriber, () => {
  14. if (hasValue) {
  15. hasValue = false;
  16. const value = lastValue;
  17. lastValue = null;
  18. subscriber.next(value);
  19. }
  20. }, noop));
  21. });
  22. }
  23. //# sourceMappingURL=sample.js.map