takeLast.js 775 B

12345678910111213141516171819202122
  1. import { EMPTY } from '../observable/empty';
  2. import { operate } from '../util/lift';
  3. import { createOperatorSubscriber } from './OperatorSubscriber';
  4. export function takeLast(count) {
  5. return count <= 0
  6. ? () => EMPTY
  7. : operate((source, subscriber) => {
  8. let buffer = [];
  9. source.subscribe(createOperatorSubscriber(subscriber, (value) => {
  10. buffer.push(value);
  11. count < buffer.length && buffer.shift();
  12. }, () => {
  13. for (const value of buffer) {
  14. subscriber.next(value);
  15. }
  16. subscriber.complete();
  17. }, undefined, () => {
  18. buffer = null;
  19. }));
  20. });
  21. }
  22. //# sourceMappingURL=takeLast.js.map